Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
205
Set Selected Tab From ViewModel
posted

Hello.  I am implementing an app based on the MVVM pattern.  One of my controls has a dockmanager with a tabgrouppane.  I need to be able to change the active tab based on a property in my viewmodel.  Here's what the xaml looks like:

ObjectDataProvider def:

<Window.Resources>
        <ResourceDictionary>

            <ObjectDataProvider x:Key="odpWizard" ObjectType="{x:Type ViewModel:WizardViewModel}" IsAsynchronous="True" />...

TabGroupPane def:

<igDock:TabGroupPane x:Name="tabGroup1" SelectionChanged="tabGroup1_SelectionChanged" DataContext="{Binding Source={StaticResource odpWizard}}" SelectedIndex="{Binding ActiveTab}">...

ViewModel def;

private int _activeTab;

public int ActiveTab
        {
            get { return _activeTab; }
            set { _activeTab = value; OnPropertyChanged("ActiveTab");  }
        }

 

What I'm missing is how to change the active tab from the ViewModel.  Thanks for the help.

Parents
  • 54937
    Offline posted

    If you are binding the SelectedIndex to your ActiveTab property then in theory you can just set your ActiveTab property and the SelectedIndex should be updated. That being said, you may not want to go this route. When an end user drags a pane, unpins a pane, floats a pane, etc. that pane will no longer be within that TabGroupPane. It may go back there depending on the interaction - e.g. when it is pinned it will be back in the container from which it was unpinned but if it is dragged out then it will be within whatever parent they dragged the pane into.

    If you want to bring an element into view then you can use the BringIntoView method of an element within the pane you want to bring into view. If it happens to be within a TabGroupPane then it will be made the selected item of that tabgroup. Note active and selected are not necessarily the same thing since you can have multiple tabgroups each with a selected item but only 1 or even none may be active. The ActivePane is the one that has keyboard focus so if you want to make something the active pane then you would call Focus on it (note it would need to be brought into view in order for the WPF framework to allow you to give it focus so you might need to call BringIntoView, UpdateLayout and then Focus).

Reply Children