Using the master part view with different types of parts

I am trying to make a presentation in which a tree structure will be displayed on one side (master), and for the selected node some information on the left (in detail), using the MVVM template.

Treeview is tied to the ViewModel collection, which is actually an abstract class. I have two classes that inherit from my abstract ViewModel, one of which represents a category, and the other a requirement.

Categories in a tree can have children, which are either categories or requirements.

Requirements cannot have children; they are just leaves.

i.e:.

  • category 1
    • requirement 1
    • subcategory 1
  • category 2
    • subcategory 2
  • category 3

I managed to display some data from an abstract class in my detailed view. My problem is that I have to display different data if a category or requirement is selected ... I do not know how to do this.

Is there a control that will allow me to display data based on the type of selected node from my tree?

Now my XAML looks like this:

<Grid DataContext="{Binding Requirements}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="350" />
        <ColumnDefinition Width="400*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>

    <TreeView 
        x:Name="treeRequirements"
        Grid.Column="0" Grid.Row="0" 
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
        ItemsSource="{Binding}">
        <TreeView.ItemContainerStyle>
            <!-- This Style binds a TreeViewItem to a PersonViewModel. -->
            <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>

        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                <TextBlock Text="{Binding Name}" />
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>

    <Grid 
        Grid.Column="1" Grid.Row="0"
        DataContext="{Binding ElementName=treeRequirements, Path=SelectedItem}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <!-- Name comes from the abstract class, so no problem -->
        <TextBlock 
            Grid.Row="0" Grid.Column="0">
            Name
        </TextBlock>
        <TextBox
            Grid.Row="0" Grid.Column="1" 
            Text="{Binding Path=Name, Mode=TwoWay}" />


    </Grid>
</Grid>

My problem is that I don’t know how to display different details depending on the type of view model represented by the selected node. I can only display the properties of an abstract class.

Any help?

EDIT

, - , . , , , .

+3
2

, . , DataTemplateSelector. .

0

HierarchicalDataTemplate , DataType . Treeview.ItemTemplate.net, .

:

<TreeView ItemsSource={Binding}>
   <TreeView.Resources>
      <HierarchicalDataTemplate DataType="{x:Type local:Type1}">
      ...
      </HierarchicalDataTemplate>
      <HierarchicalDataTemplate DataType="{x:Type local:Type2}">
      ...
      </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>

( , , HierarchicalDataTemplate: http://msdn.microsoft.com/en-us/library/ms742521.aspx

+2

All Articles