How can I switch tabs programatically from within my ViewModel?

南笙酒味 提交于 2019-12-06 03:36:26

Try binding to the SelectedIndex property to switch to a Tab.

Not sure what MVVM framework you're using, but a possible solution is to have a ViewModel for each tab, with a parent ViewModel.

Then the parent ViewModel can activate the relevant child ViewModel, which will then activate the correct View.

Create an IsSelected property on your viewmodel that you can databind to the tabitem's IsSelected property

From MVVM perspectives ViewModel should NOT be aware of View details like TabContainer and so on, so for ViewModel it does not matter whether on underlying View used TabContainer or ListView control. So consider something straightforward like simple IEnumerable<IRepresentationItem> Items to be exposed by ViewModel and then bound to UI items container of the underlying View.

And obviously expose SelectedItemIndex property which could be bound to corresponding SelectedTab/SelectedItem Index of UI Items container.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!