问题描述
我有类作为ModuleInitialization注册相应的视图。
我有以下视图。
CustomerMainView
StockMainVIew
SupplierMainView
----注册StockMainView的代码------
container.RegisterType< stockmainviewviewmodel> ();
container.RegisterType< object,Menu.Menu>();
this.container.RegisterType< object,StockMainView>(typeof(StockMainView).Name) ;
this.regionManager.RegisterViewWithRegion(RegionNames.ModulesMenuRegion,typeof(Menu.Menu));
-----------结束--- --------------------------
其对应的ViewModel是
CustomerMainViewViewModel
StockMainViewViewModel
SupplierMainViewViewModel
现在我需要3个按钮,如客户,股票,供应商....所以当我点击Customer时,Customer视图应该得到D.相应地显示了其他人。
这个视图是UserControl WPF所以我无法使用.Show()方法....
先谢谢..
I have classes as ModuleInitialization which registers the appropriate Views.
I have the following view.
CustomerMainView
StockMainVIew
SupplierMainView
----the code to register StockMainView------
container.RegisterType<stockmainviewviewmodel>();
container.RegisterType<object, Menu.Menu>();
this.container.RegisterType<object, StockMainView>(typeof(StockMainView).Name);
this.regionManager.RegisterViewWithRegion(RegionNames.ModulesMenuRegion, typeof(Menu.Menu));
-----------End-----------------------------
Its corresponding ViewModels are
CustomerMainViewViewModel
StockMainViewViewModel
SupplierMainViewViewModel
Now I need 3 Buttons like Customer,Stock,Supplier....so when I click on Customer the Customer view should get Displayed and hence the others accordingly.
This views are UserControl WPF so I am not able to use .Show() method....
Thanks in advance..
推荐答案
<contentcontrol content="{Binding CurrentView}"></contentcontrol>
并将其绑定到ViewModel中的属性
and bind it to a property in your ViewModel
private object currentView;
public object CurrentView
{
get
{
return currentView;
}
set
{
if(currentView != value)
{
currentView = value;
OnPropertyChanged();
}
}
}
假设您调用了用户控制视图,例如UcViewBlue和UcViewRed
您可以通过激活ChangeCommandBlue命令切换到UcViewBlue。
Assuming you User Control views are called e.g. UcViewBlue, and UcViewRed
you could switch to "UcViewBlue" by excuting the "ChangeCommandBlue" Command.
private RelayCommand changeCommandBlue;
public ICommand ChangeCommandBlue
{
get
{
if (changeCommandBlue == null)
{
changeCommandBlue = new RelayCommand(param => this.ChangeBlue());
}
return changeCommandBlue;
}
}
private void ChangeBlue()
{
CurrentView = new UcViewBlue();
}
祝你好运,
Stephan
Best regards,
Stephan
这篇关于如何在按钮上显示Usercontrol Wpf页面单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!