Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4083346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:18:05+00:00 2026-05-20T18:18:05+00:00

I try to make a view that will display a treeview on one side

  • 0

I try to make a view that will display a treeview on one side (master), and for the selected node, some information on the left (detail), using the MVVM pattern.

The treeview is bound on a collection of a ViewModel that is, in fact, an abstract class. I have two classes that inherits from my abstract ViewModel, one representing a category, the other one a requirement.

In the tree, the categories may have childs that are either categories or requirements.

The requirements cannot have childs, they are just leaves.

i.e.:

  • category 1
    • requirement 1
    • sub-category 1
  • category 2
    • sub-category 2
  • category 3

I managed to display some data from the abstract class in my detail view. My problem is that I have to display different data if a category or a requirement is selected… I have no clue how to do this.

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

My XAML looks like this for now:

<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, I have no idea how to display different details based on the type of the viewmodel represented by the selected node. I am only able to display properties of the abstract class.

Any help?

EDIT

To sum up my question, the whole master-detail and treeview are pretty irrelevant to the problem, there are just to put in context. My problem is really just to display different fields based on the subtype of my viewmodel, which may vary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:18:06+00:00Added an answer on May 20, 2026 at 6:18 pm

    I was curious about your question, so I did some looking around myself. It looks like you might want to use a DataTemplateSelector. There’s a nice example shown here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to C# but I will try to make this quick! ;)
I have a bowling web application that allows pretty detailed frame-by-frame information entry. One
I will try to make myself as clear as possible. Let start from the
I'll try to make this as straight forward as possible. Currently our team has
When I try to make a very large boolean array using Java, such as:
If we make any class in VB.NET and try to access its property in
is it possible to make beep in WinCE ? i try and i get
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try
I have the following interface which I'm trying to make COM-visible. When I try
I've got a view in Django that uses memcached to cache data for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.