[英]MVVM select new Tab from TabControl
I want to select tab from tab control after creating it. 我要在创建标签后从标签控件中选择标签。
XAML: XAML:
<TabControl SelectedIndex="{Binding SelectedTabIndex}" Name="Items">
<TabControl.Resources>
</TabControl.Resources>
</TabControl>
MainViewModel: 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
ChartViewModel
是从Caliburn.Micro.Screen
继承的类, MainViewModel
从Caliburn.Micro.Conductor<Caliburn.Micro.Screen>.Collection.OneActive
ChartViewModel
继承的类。
The tab is created properly, but it is not selected after that. 该选项卡已正确创建,但此后未选择。
Change your xaml code to something like this, 将您的xaml代码更改为类似的内容,
<TabControl SelectedIndex="{Binding SelectedTabIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Name="Items">
<TabControl.Resources>
</TabControl.Resources>
</TabControl>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.