I've created a hierarchical data structure using ObservableCollection<T> where each item contains a public ObservableCollection<T> to connect to the next node. The data structure is similar to the one in the DataUtil class which is in your DataTreeBinding example.
The problem is that only the root node gets displayed and I don't see an Expand Icon where I know there are sub-nodes in the data. What is the requirement in order to get the XamDataTree to recognize there are sub-nodes?
I'm binding in code like this:this.MyTree.DataContext = m_menuData;this.MyTree.ItemsSource = m_menuData.Centers;where m_menuData is the object that contains the data and m_menuData.Centersis the ObservableCollection<T> that contains the data hierarchy.
Hi,
Could you post the definition of your data structure?
It is important to define the NodeLayout before the XamDataTree can display the child levels. If layouts are defined in the GlobalNodeLayout collection, you need to make sure that the Key property corresponds to the property name that is of type ObservableCollection<T> and TargetTypeName is the string name of the type of the items (T).
HTH,
Thank you for your prompt response!
My actual data structure is way too much to post. If needed, I'll later try to create a simplified version that shows the essentials.
In regards to the GlobalNodeLayout (which I am using), I thought the Key property was an arbitrary name for the Node Layout provided just so the NodeLayout could be referenced in code. So, I didn't understand your comment "...make sure that the Key property corresponds to the property name that is of type ObservableCollection<T>". Could you please explain that further.
Regarding your comment "TargetTypeName is the string name of the type of the items (T)", I think herein my lay my problem. My instantiation of ObservableCollection<T> is actually ObservableCollection<TBaseClass> and in my NodeLayout definitions I'm referencing Derived classes with the TargetTypeName property. There's no way for me to know the type of a given node at design time.
Is there any way to make this work?
Thanks again,
Joe
Thanks, but I don't understand your sample and how it relates to my problem. Perhaps I haven't explained my problem well enough or maybe your sample does apply and I just don't get it.
One thing about your sample that really baffles me is that in your XAML you have this:TargetTypeName="ITestData", In the solution there is no interface named "ITestData". There is "IChildTestData" but not "ITestData". So, how is this working? I have run the application so I know it does work.
I think for now, I'm going to forgo trying to do this with databinding and revert back to using XamTree where I can explicitly create the tree nodes in code.
I would appreciate your addressing my question above about "ITestData". I apparently don't understand C# and XamDataTree as well as I should.
Thank you very much for your assistance.
Yes, you are right - the ITestData in the sample is wrong, sorry about that. The actual value should have been IChildTestData and the sample is working because obviously the XamDataTree is able to match the date by the specified Key value.
As you can see, the IChildTestData is used as ObservableCollection<T> type parameter, so it is just as in your case when you have a base class specified and that's what I tried to demonstrate - wasn't that one of your questions?
What else do you think is not addressed by the sample?
Yes, that was one of my questions and I'm sure given time I'll see the light and understand it all. But right now, unfortunately due to time constraints, I have a working tree using XamTree. I will have to pursue this approach later. I would much prefer to use databinding.
One thing I'm still failing to understand is the role played by the Key value (as in Key="CategoryLayout"). Could you elaborate on your statement: "...the sample is working because obviously the XamDataTree is able to match the data (? spelling): I assume data was meant) by the specified key value." Based on the sample, "DataTreeBinging" solution,which shows Key="CategoryLayout" and TargetTypeName="Category", I had the impression that TargetTypeName is used to match up with the data. Is that a wrong assumption on my part. If so, what role does TargetTypeName play?
Thanks again for your help!
The process of assigning a layout is really complex - so if we start from the root, the tree examines the items from the data source and tries to match with a NodeLayout defined as global layout, by the TargetTypeName.
Also, each item's IEnumerable properties are checked and matched against NodeLayout-s Key property, if a match is found the the layout for the child level is assigned. Otherwise, the tree falls back to matching the item type of that IEnumerable to TargetTypeName property of the NodeLayout-s.
The process goes further for all levels.
Note: the process described is for the case with NodeLayout-s defined in the GlobalNodeLayouts collection.
I hope that clarifies things a bit.
That helps. Thank you.