Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经实现了 MVVM 模式,并且有一些视图模型绑定到选项卡控件上的选项卡页。
当特定对象类型更改(即从 Car myVehical 到 Bike myVehical)时,我希望相关的标签页被选中。
谢谢。
您可以使用自定义破解IValueConverter它。然后,您可以绑定TabControl.SelectedIndex到视图模型上的属性并使用转换器将类型(汽车或自行车)转换为索引。更改选项卡时必须更新值转换器代码。
IValueConverter
TabControl.SelectedIndex
您可以使用 DataTemplates,而不是使用选项卡控件。视图本身将根据您设置为内容的对象自动设置。