简体   繁体   中英

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.

Change your xaml code to something like this,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM