本文介绍了MVVMLight UserControl View Model-为每个视图创建新的用户控件实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对在其他视图中使用的患者列表进行了用户控制.但是,当我选择其中一个患者时,选择会传播到包含用户控件实例的所有视图.如何让每个视图为每个视图实例化一个新的用户控件实例?我正在使用 C#
I have a user control of list of Patients which I use in other Views. However when I choose one of the Patients, the selection is propagated to all the views containing an instance of the user control. How can I make each view instantiate a new instance of the user control for each view? I am using c#
推荐答案
根据您所说的猜测,我假设您从定位器返回 PatientViewModel 的静态实例.要解决这个问题,请确保在调用该属性时生成一个新的视图模型实例.
Guessing from what you stated, I'd assume that you returning a static instance of you PatientViewModel from you locator. To solve this make sure that when the property is called a new instance of the view model is generated.
具有不同实例化方法的定位器
public class ViewModelLocator
{
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
//if (ViewModelBase.IsInDesignModeStatic)
//{
// // Create design time view services and models
// SimpleIoc.Default.Register<IDataService, DesignDataService>();
/
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!