Sam King
Sam King

Reputation: 85

Tabitem not getting selected from viewmodel

I am unable to select the tabitem from viewmodel , i tries with isselected and selectedindex but it still doesn't work.

Viewmodel:

      public int _selectedIndex;
    public int SelectedTabIndex
    {
        get { return _selectedIndex; }
        set
        {
            if (_selectedIndex != value)
            {
                _selectedIndex = value;
                //if (RaisePropertyChanged != null)
                    RaisePropertyChanged("SelectedIndex");
            }

        }
    }

XAML Code:

 <TabItem Header="Fault Code Table" DataContext="{Binding TESTModel, Source={StaticResource Locator}}" IsEnabled="True" TabIndex="{Binding Path=SelectedTabIndex ,Mode=TwoWay}"  >
                            <StackPanel>
                                <local:FaultCodeTable />    
                            </StackPanel>
                        </TabItem>

Upvotes: 0

Views: 54

Answers (1)

mm8
mm8

Reputation: 169200

You should bind the SelectedIndex property of parent TabControl to your source property:

<TabControl SelectedIndex="{Binding SelectedTabIndex}">...

An individual TabItem has an IsSelected property that you can use to determine whether it's currently selected. It has no concept of any selected index though because it is not an ItemsControl.

Upvotes: 1

Related Questions