MVVMLight UserControl View Model-Create new Instance of User control for each view(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>();
/
本文标题为:MVVMLight UserControl View Model-为每个视图创建新的用户控件实例
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01