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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:08:06+00:00 2026-05-26T04:08:06+00:00

In the current project we work on, we have a main window with several

  • 0

In the current project we work on, we have a main window with several views (each with its own viewmodel) that are presented as items in a tab control. E.g: One tab item is an editor, and contains the editor view as follows:

<TabItem Header="Test Editor">
            <TestEditor:TestEditorView DataContext="{Binding TestEditorViewModel}"/>
</TabItem>

Another one shows results:

<TabItem Header="Results Viewer">
     <ResultViewer:ResultViewer x:Name="resultViewer1" DataContext="{Binding Path=ResultViewModel}"  />
</TabItem>

etc.
I’d like to have the TabItems bound to something in the main window’s viewmodel, but I can’t figure out how to bind the view’s name to any property without breaking the MVVM pattern. I’d like to have something like:

 <TabControl.ContentTemplate>
     <DataTemplate>
         <TestEditor:TestEditorView DataContext ="{Binding TabDataContext}"/>
     </DataTemplate>
 </TabControl.ContentTemplate>

only with some binding instead of having to know at design time what type will be used as content.
Any ideas?

  • 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-26T04:08:06+00:00Added an answer on May 26, 2026 at 4:08 am

    Usually I have the TabControl’s Tabs stored in the ViewModel, along with the SelectedIndex, then I use DataTemplates to determine which View to display

    View:

    <Window>
        <Window.Resources>
            <DataTemplate DataType="{x:Type ResultViewModel}">
                <ResultViewer:ResultViewer />
            </DataTemplate>
            <DataTemplate DataType="{x:Type EditorViewModel}">
                <TestEditor:TestEditorView />
            </DataTemplate>
        </Window.Resources>
    
        <TabControl ItemsSource="{Binding TabCollection}"
                    SelectedIndex="{Binding SelectedTabIndex}" />
    
    </Window>
    

    ViewModel:

    public class MyViewModel : ViewModelBase
    {
    
        publicMyViewModel()
        {
            TabCollection.Add(new ResultsViewModel());
            TabCollection.Add(new EditorViewModel());
            SelectedTabIndex = 0;
        }
    
        private ObservableCollection<ViewModelBase> _tabCollection
            = new ObservableCollection<ViewModelBase>();
    
        public ObservableCollection<ViewModelBase> TabCollection
        {
            get { return _tabCollection };
        }
    
        private int _selectedTabIndex;
        public int SelectedTabIndex
        {
            get { return _selectedTabIndex; }
            set
            {
                if (value != _selectedTabIndex)
                {
                    _selectedTabIndex = value;
                    RaisePropertyChanged("SelectedTabIndex");
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a current project running using APE that needs to work on C#/.NET...
for my current project I am starting to work with AS3 and I have
On my current project, I am using FxCop to work through various code analysis
My current project involves deploying an upgraded .exe file that runs as a Windows
This is my current project structure: pom.xml /src /main /resources hibernate.cfg.xml /META-INF persistence.xml I
I have the following project structure which I can't get to work: Mac OS
I have a design idea for a large project at work and I think
I have isolated very strange bug from our current project: index.html (demo) and iframe.html
Background I have a Windows service that uses various third-party DLLs to perform work
I'm wondering if this is going to work... Say i have a project template

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.