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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:47:22+00:00 2026-05-30T10:47:22+00:00

I’m having some issues with the wpf tab control. Not sure the title of

  • 0

I’m having some issues with the wpf tab control. Not sure the title of the question is right I will refine it accoring to answers.

I want to create a simple panel system. I want to inject ot my “panel viewModel” 2 view model

  • MainViewModel will be display as the main area
  • PanelViewModel will be display as a panel on the right hand side of the view

the panelViewModel will be hidden by default and a button will display it on top of the main view model when needed

The view look like this:

<UserControl.Resources>
 <DataTemplate x:Key="MainWindowTemplate" DataType="{x:Type UserControl}">
  <ContentPresenter Content="{Binding DataContext.MainViewModel, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
 </DataTemplate>
</UserControl.Resources>

<Grid>

 <Grid Visibility="{Binding IsPanelHidden, Converter={StaticResource bool2VisibilityConverter}}">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="Auto"/>
  </Grid.ColumnDefinitions>

  <ContentControl Grid.Column="0" ContentTemplate="{StaticResource MainWindowTemplate}" />

  <Button Grid.Column="1" Content="{Binding PanelTitle}" Command="{Binding Path=ShowPanelCommand}">
    <Button.LayoutTransform>
      <RotateTransform Angle="90"/>
    </Button.LayoutTransform>
  </Button>
 </Grid>

<Grid Visibility="{Binding IsPanelHidden, Converter={StaticResource revertBool2VisibilityConverter}}">

  <ContentControl ContentTemplate="{StaticResource MainWindowTemplate}" />

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="0.5*"/>
    </Grid.ColumnDefinitions>

    <Border Grid.Column="2" VerticalAlignment="Stretch" Background="Red" >
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border HorizontalAlignment="Stretch">
          <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0" Text="{Binding PanelTitle}" Margin="5,5,0,2" HorizontalAlignment="Left"></TextBlock>
            <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0,0,5,0" HorizontalAlignment="Right" >
              <Button Content="Minimze" Command="{Binding HidePanelCommand}"/>
            </StackPanel>
          </Grid>
        </Border>

        <ContentPresenter Grid.Row="1" Margin="2" Content="{Binding PanelViewModel}" VerticalAlignment="Top"/>
      </Grid>
    </Border>
  </Grid>
</Grid>

The view model look like that:

public class TestTabViewModel : ObservableObject
{
    #region private attributes

    #endregion

    public TestTabViewModel(string panelName, object panelViewModel, object mainViewModel)
    {
        IsPanelHidden = true;
        PanelTitle = panelName;
        PanelViewModel = panelViewModel;
        MainViewModel = mainViewModel;
        ShowPanelCommand = new DelegateCommand(() =>ManagePanelVisibility(true));
        HidePanelCommand = new DelegateCommand(() => ManagePanelVisibility(false));
    }

    #region properties


    public string PanelTitle { get; private set; }

    public bool IsPanelHidden { get; private set; }

    public object PanelViewModel { get; private set; }

    public object MainViewModel { get; private set; }

    public DelegateCommand ShowPanelCommand { get; private set; }

    public DelegateCommand HidePanelCommand { get; private set; }

    #endregion

    #region private methods

    private void ManagePanelVisibility(bool visible)
    {
        IsPanelHidden = !visible;
        RaisePropertyChanged(() => IsPanelHidden);
    }

    #endregion
}

So for so good, this system work fine I aslo added some pin command but I remove them from here to make it “simple”.

My problem come when the main view model hold a tab control. In this, case if I select a tab and “open” the panel, the tab selected is “changed”. In fact it’s not changed it’s just that I display another contentControl which is not synchronize with the previouse one. I guess that the view instance is not the same even if the viewmodel behind is.

So how do I share a view instance within a view (or have the selection process synchornized)? My first guest was to use the datatemplate (as show in the example) but it did not solve my problem.

By the way, I know some third-party handling panel docking pin … (eg avalon) but all the one I found are really too much for my simple need.

Thanks for the help

  • 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-30T10:47:23+00:00Added an answer on May 30, 2026 at 10:47 am

    Your best bet would probably be to replace your two Grids with a single ContentControl, and switch the Template on button click or in a Trigger. This way your actual Content (the TabControl) will be the same, but the template used to display the Content will change

    Here’s a quick example:

    <Window.Resources>
        <ControlTemplate x:Key="Grid1Template" TargetType="{x:Type ContentControl}">
            <DockPanel>
                <Grid Background="CornflowerBlue" Width="100" DockPanel.Dock="Left" />
                <ContentPresenter Content="{TemplateBinding Content}" />
            </DockPanel>
        </ControlTemplate>
    
        <ControlTemplate x:Key="Grid2Template" TargetType="{x:Type ContentControl}">
            <DockPanel>
                <Grid Background="CornflowerBlue" Width="100" DockPanel.Dock="Right" />
                <ContentPresenter Content="{TemplateBinding Content}" />
            </DockPanel>
        </ControlTemplate>
    </Window.Resources>
    
    <DockPanel>
        <ToggleButton x:Name="btnToggle" Content="Toggle View" DockPanel.Dock="Top" />
        <ContentControl>
            <ContentControl.Style>
                <Style TargetType="{x:Type ContentControl}">
                <Setter Property="Template" Value="{StaticResource Grid1Template}" />
                <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=btnToggle, Path=IsChecked}" Value="True">
                            <Setter Property="Template" Value="{StaticResource Grid2Template}" />
                    </DataTrigger>
                </Style.Triggers>
                </Style>
            </ContentControl.Style>
    
            <TabControl>
                <TabItem Header="Tab1" />
                <TabItem Header="Tab2" />
                <TabItem Header="Tab3" />
            </TabControl>
        </ContentControl>
    
    </DockPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm having trouble keeping the paragraph square between the quote marks. In firefox 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.