Jaroslaw Matlak
Jaroslaw Matlak

Reputation: 574

MVVM select new Tab from TabControl

I want to select tab from tab control after creating it.

XAML:

<TabControl SelectedIndex="{Binding SelectedTabIndex}" Name="Items">
      <TabControl.Resources>
      </TabControl.Resources>
</TabControl>

MainViewModel:

public int SelectedTabIndex
{
   get
   {
      return Items.Count - 1;
   }
   set { ; }
}
public void AddTab()
{
   var chart = new ChartViewModel(this.eventAggregator, this.windowManager);
   NotifyOfPropertyChange(() => SelectedTabIndex);
}

ChartViewModel is a class inherited from Caliburn.Micro.Screen, MainViewModel inherits from Caliburn.Micro.Conductor<Caliburn.Micro.Screen>.Collection.OneActive

The tab is created properly, but it is not selected after that.

Upvotes: 1

Views: 344

Answers (1)

Vijay
Vijay

Reputation: 673

Change your xaml code to something like this,

<TabControl SelectedIndex="{Binding SelectedTabIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Name="Items">
      <TabControl.Resources>
      </TabControl.Resources>
</TabControl>

Upvotes: 4

Related Questions