Le réseau pour les développeurs > Forums - Accueil > Windows Presentation Foundation (WPF) > TreeView CollectionViewGroupInternal Object Type
Poser une questionPoser une question
 

QuestionTreeView CollectionViewGroupInternal Object Type

  • mercredi 4 novembre 2009 13:16Igor Kondrasovas Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code

    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:

     if (e.NewValue.GetType() == typeof(OtimizeDAL.Material))<br/>...<br/>...<br/>
    
    However, this test always fails, because the NewValue is of type 'CollectionViewGroupInternal', insted of the type of the object I'm grouping data.

    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

Toutes les réponses

  • vendredi 6 novembre 2009 14:41Jim Zhou - MSFTModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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