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


- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01