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 5973469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:48:16+00:00 2026-05-22T20:48:16+00:00

I have a TreeView control on my window that depending on which selection the

  • 0

I have a TreeView control on my window that depending on which selection the user picks should display a user control (figuring out which user control to display is complete). I’m having issues figuring out how to actually display the user control. Essentially, the user would select item from the TreeView and based on the selection a user control would appear (in a ContentControl control I’m assuming).

Currently, for opening new windows I have a window adapter where I can create new windows on the fly and set the parent.

How can I accomplish this in my view model?

Edit

Here is what I believe Rachel was talking about when she mentioned using DataTemplate‘s instead. Don’t be worried of my DataTemplates instead the DataType attribute. That’s simply the name of my project.

<Window.Resources>
    <DataTemplate DataType="{x:Type DataTemplates:FooEditorViewModel}">
        <DataTemplates:FooControl></DataTemplates:FooControl>
    </DataTemplate>
    <DataTemplate DataType="{x:Type DataTemplates:BarEditorViewModel}">
        <DataTemplates:BarControl></DataTemplates:BarControl>
    </DataTemplate>
</Window.Resources>

And here is a sample view model.

public class ViewModel
{
    public IEditorViewModel Editor
    {
        get
        {
            return new BarEditorViewModel();
        }
    }
}

And glue it all together with

<ContentControl Content="{Binding Editor}" />

I had to create a blank interface called IEditorViewModel in order to return different user control editors. Not sure if there’s any way around it.

Hopes this helps someone.

  • 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-22T20:48:17+00:00Added an answer on May 22, 2026 at 8:48 pm

    Your SelectedTreeViewItem would be stored in your ViewModel, and that value would be used to determine which item to display.

    An example would be something like:

    <ContentControl Content="{Binding SelectedItem}">
        <ContentControl.Style>
            <Style TargetType="{x:Type ContentControl}">
                <Setter Property="ContentTemplate" Value="{StaticResource DefaultTemplate}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SelectedItem}" Value="{x:Type local:ItemA}">
                        <Setter Property="ContentTemplate" Value="{StaticResource TemplateA}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding SelectedItem}" Value="{x:Type local:ItemB}">
                        <Setter Property="ContentTemplate" Value="{StaticResource TemplateB}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
    

    A better alternative is to use DataTemplates for different Items. Then you just set your Content="{Binding SelectedItem}" and WPF will resolve the correct DataTemplate to use. I just showed the above example first because it can be used to base your Template off a Property of SelectedItem

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

Sidebar

Related Questions

I have a treeview control in a Windows Forms project that has checkboxes turned
I have a TreeView control in my WinForms .NET application that has multiple levels
I have a treeview control that functions like a folder browser. Because loading the
Using WPF, I have a TreeView control that I want to set its ItemTemplate
Hi The problem am having is that I have multiple TreeView control and each
I have a TreeView control in a Windows Forms application that is displaying my
I have a page that uses a TreeView control from ComponentArt. If I add
I have a control that inherits from TreeView (System.Windows.Controls.TreeView from WPF Framework) and it
I have a treeview control which is being used to browse various folder on
I have my own custom control derived from System.Windows.Forms.TreeView which is present on 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.