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

  • Home
  • SEARCH
  • 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 3969056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:55:04+00:00 2026-05-20T03:55:04+00:00

I need to design a form with a treeview in the left and a

  • 0

I need to design a form with a treeview in the left and a container for some other control in the remaining area. Whenever user selects an item in the treeview some custom control appears on the right. For example, let’s say that the treeview contains values “Audio settings” and “Video settings”, and I have two controls that can be bound to these settings and I want to display them on the form when needed.

Now, from what I’ve read about MVVM, I shouldn’t have properties that will return UserControls or DataTemplates, am I right? It will be messing with “VM shouldn’t know implementation details of the view” as I see it. So, how do I handle this situation properly in terms of MVVM? Should I maybe use converters for this and if so, how would it look?

I can’t provide any code at the moment (mostly because there isn’t any), but I will try to clarify the problem if needed.
Thanks in advance.

  • 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-20T03:55:05+00:00Added an answer on May 20, 2026 at 3:55 am

    This is where the WPF templating system helps out.

    The main idea is to have a ContentControl display the appropriate view depending on the selected value in the TreeView.

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">
        <DockPanel>
    
            <ListBox DockPanel.Dock="Left" ItemsSource="{Binding Editors}" SelectedItem="{Binding SelectedEditor}" />
    
            <ContentControl Content="{Binding SelectedEditor}">
                <ContentControl.Resources>
                    <DataTemplate DataType="{x:Type l:VideoViewModel}">
                        <l:VideoView />
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type l:AudioViewModel}">
                        <l:AudioView />
                    </DataTemplate>
                </ContentControl.Resources>
            </ContentControl>
    
        </DockPanel>
    </Window>
    

    AudioView and VideoView are UserControls.

    As you can see, the ContentControl‘s content is bound to the SelectedEditor property in the ViewModel, which is also bound to the SelectedItem of the Listbox.

    So the ViewModel for the main view looks like this.

    public class MainWindowViewModel : INotifyPropertyChanged
    {
        public IEnumerable<object> Editors
        {
            get
            {
                yield return new VideoViewModel();
                yield return new AudioViewModel();
            }
        }
    
        private object selectedEditor;
        public object SelectedEditor
        {
            get { return selectedEditor; }
            set
            {
                if (selectedEditor == value)
                    return;
                selectedEditor = value;
                OnPropertyChanged("SelectedEditor");
            }
        }
    }
    

    So you can see that the main ViewModel has no GUI data in it.

    To handle hooking up a TreeView to a SelectedItem property in a ViewModel see Data binding to SelectedItem in a WPF Treeview

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

Sidebar

Related Questions

We need some input on what is a good design pattern on using AJAX
I need some resources that talk about how to design your software to be
There is a pretty strong need for us to design some workflows around various
I need to design an order form where one row represents and order line
I need to design a small project for generating excel reports in .NET, which
I need to design a notifications framework written solely in .Net. I was wondering
I often need to design a dialog in Delphi/C++Builder that allows various properties of
Maybe the need to do this is a 'design smell' but thinking about another
We need to generate LINQ queries which are 100% unknown during coding (design time).
I need to bind labels or items in a toolstrip to variables in Design

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.