MVVMLight UserControl View Model-为每个视图创建新的用户控件实例

MVVMLight UserControl View Model-Create new Instance of User control for each view(MVVMLight UserControl View Model-为每个视图创建新的用户控件实例)
本文介绍了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>();
            /
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)