Hi,
I am trying to create a categorized view that I want to represent here as a simple category/list of object names. I was able to do it using the TreeView but I am having troubles doing the same using the xamTreeGrid, which I need to use. Any help would be greatly appreciated!
the view model is:
List<KeyValuePair<string, List<BaseObject>>> ListOfCatObjects
using a regular TreeView:
<TreeView Name="treeViewCategorized" ItemsSource="{Binding ListOfCatObjects}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Value}">
<TextBlock Text="{Binding Path=Key}" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Thanks in advance,
Maria
Hello Maria,
I believe you are going to have a rather difficult time implementing this type of behavior in the XamTreeGrid, and this is due to the way that the XamTreeGrid works with its data. The XamTreeGrid expects a largely homogeneous structure, but it can support heterogeneous data. There are constraints on the heterogeneous data, though, as the parent level data type needs to have property definitions for each of the properties that exist as part of its child bands, exclusive of the property used for the hierarchical structure.
In your case, with the KeyValuePair, you run into some issues here for a couple of different reasons. First, the KeyValuePair only exposes two properties, Key and Value, and currently your Value property is being used for the hierarchical structure. The second problem is that KeyValuePair is a sealed class, and so it cannot be derived from. This means that you could only ever show a property for "Key" in your child band, as you would not be able to add additional properties to the KeyValuePair class.
This may be somewhat confusing, and so I have attached a sample project to demonstrate usage of heterogeneous data in the XamTreeGrid.
It is for the reasons above that I would probably recommend against using the XamTreeGrid with KeyValuePairs, and rather, use a control such as the XamDataGrid or the XamDataTree. You can read about both in the following articles, and if you would like me to demonstrate these controls to you, please feel free to ask:
XamDataGrid: http://ko.infragistics.com/help/wpf/xamdata-displaying-hierarchical-data.
XamDataTree: http://ko.infragistics.com/help/wpf/xamdatatree-xamdatatree-data-binding.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
thank you for the quick reply! I was hoping to use my current view model and just do the right magic in xaml but sure, I can adjust the vm to feed the control better. I just wish I would have asked earlier :)