作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不想把它全部放在一个 ViewModel 中,我希望每个 tabItem 有一个 viewModel。
我为包含 TabControl 的窗口创建了一个 mainViewModel,其中我有这个属性 currentViewModel,指向 mainViewModel 构造函数的默认值
public MainViewModel()
{
currentViewModel = "viewModel1";
}
currentViewModel = "viewModel2";
public String currentViewModel
{
get { return _currentViewModel; }
set
{
_currentViewModel = value;
OnPropertyChanged("currentViewModel");
}
}
最佳答案
我认为一个好的方法是为每个选项卡项创建用户控件。然后,在每个用户控件中,您将引用要绑定(bind)到的正确 viewModel 命名空间。
您的 MainWindow 将具有 tabcontrol,并且 tabcontrol 内的每个 tabitem 都将绑定(bind)到特定的用户控件(被视为单独的 View )。
mainwindow_View.xaml 将绑定(bind)到 mainwindow_ViewModel.cs
tabItem1_View.xaml 将绑定(bind)到 ViewModel1.cs
tabItem2_View.xaml 将绑定(bind)到 ViewModel2.cs
如果您需要代码示例,请告诉我。
关于.net - 如何将不同的 tabItems 绑定(bind)到不同的 ViewModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5737476/
我是一名优秀的程序员,十分优秀!