.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
TreeView CollectionViewGroupInternal Object Type
TreeView CollectionViewGroupInternal Object Type
Hello,
Currently I'm displaying data on a wpf treeview control and the objects bound to it are hierarchically defined using grouping definitions
This is working fine, but I must perform some tests whe the user selects an item on the treeview. When the user clicks on a group node, the selecteditemchanged event is fired and then i use something like:However, this test always fails, because the NewValue is of type 'CollectionViewGroupInternal', insted of the type of the object I'm grouping data.if (e.NewValue.GetType() == typeof(OtimizeDAL.Material))<br/>...<br/>...<br/>
How can I perform a test to make sure I'm selecting a "Material" group node?
My XAML is defined as:
<CollectionViewSource x:Key="MaterialProcessingSource"> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription PropertyName="ProductionOrder"> </PropertyGroupDescription> <PropertyGroupDescription PropertyName="Material"> </PropertyGroupDescription> </CollectionViewSource.GroupDescriptions> </CollectionViewSource> <DataTemplate x:Key="repositoryTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=width}"/> <TextBlock Text=" X "/> <TextBlock Text="{Binding Path=length}"/> </StackPanel> </DataTemplate> <HierarchicalDataTemplate x:Key="detailDataTemplate" ItemsSource="{Binding Path=Items}" ItemTemplate="{StaticResource repositoryTemplate}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Items[0].Material.code }"/> <TextBlock Text=" - "/> <TextBlock Text="{Binding Items[0].Material.description }"/> </StackPanel> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="materialDataTemplate" ItemsSource="{Binding Path=Items}" ItemTemplate="{StaticResource detailDataTemplate}"> <TextBlock Text="{LocText Key=MATERIALS, Dict=Resources, Assembly=OtimizeStandard}"></TextBlock> </HierarchicalDataTemplate>
Project Manager at INOVATIVA Tecnologia www.inovativatec.com
All Replies
- Hi Igor Kondrasovas,
Since the underlying data source for TreeViewItem is the data item, so have you checked out the DataContext property of TreeViewItem? The DataContext is holding the data for the item in TreeView.
If you have any issues, please feel free to feed back.
Thanks.
Sincerely.
Jim Zhou -MSFT


