如何从我的 ViewModel 中以编程方式切换选项卡? [英] How can I switch tabs programatically from within my ViewModel?

查看:72
本文介绍了如何从我的 ViewModel 中以编程方式切换选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MVVM 桌面应用程序.在我的视图中,我有一个 TabControl.

I have a MVVM desktop application. In my View, I have a TabControl.

关于通过更改 ViewModel 上的属性切换到特定选项卡的最佳做法有什么建议吗?

Any suggestions on the best practice to switch to a specific tab by changing a property on the ViewModel?

我想它可以用 SelectedTab 属性来完成,但是选项卡必须存在于 ViewModel 中,并且视图必须绑定到 ViewModel 中的选项卡列表.目前,这两个选项卡是静态的,因为我不会在执行期间动态创建/删除任何选项卡.所以我在视图中创建了选项卡,它们代表绑定到同一个 ViewModel 的两组不同的控件,所以这不是不同视图模型实例的不同选项卡的情况.

I suppose it could be done with a SelectedTab property, but then the Tabs have to exist in the ViewModel, and the View must bind to the Tabs list in ViewModel. At the moment, the two tabs are static, in the sence that I won't be creating/deleting any dynamically during execution. So I create the tabs in the View, and they represent two different sets of control bound to the same ViewModel, so it's not a case of different tabs for different view model instances.

推荐答案

尝试绑定到 SelectedIndex 属性以切换到选项卡.

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

这篇关于如何从我的 ViewModel 中以编程方式切换选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆