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-为每个视图创建新的用户控件实例


基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03