c# - WPF中Catel的问题,InterestedIn ViewModel重载
问题描述
所以我有一个名为 NewBonusCalculationViewModel 的视图模型。此ViewModel对其他一些视图模式感兴趣,这些视图模型是NewBonuscalculationViewModel中的标签。
NewBonusCalculationViewModel 感兴趣的选项卡之一称为 GeneralTabVM。此 GeneralTabVM 有一个名为 GeneralTabDataModel 的数据模型,数据模型中的属性与 GneralTabVM(ViewModelToModel) 进行映射。
在 GeneralTabDataModel 我有一个名为 StartingTime 的属性,当我打开 NewBonusCalculationViewModel 页面并点击 X 按钮(不做任何更改)时,viewmodel 类型会重置 StartingTime 属性的值,这会引发 IsModelDirtyChanges 并且我得到问题“你要保存更改吗?”。
我找不到导致视图模型重置或重新加载的原因。我正在使用 Catel 4.4。
我尝试删除映射,interestedIn,甚至删除属性 StartingTime(并使用 Model.StartingTime),但似乎没有任何效果。
这就是我从 NewBonusCalcVieModel 加载 GeneralTab 道具的方式:
generalModel = new GeneralTabDataModel
{
Header = Client.Common.GetText(456),
Id = LohnStatList[0].Id,
Descript = LohnStatList[0].Descript,
IdGroup = LohnStatList[0].IdGroup,
IdStation = LohnStatList[0].IdStation,
SelectedStationName = this.AllStations.FirstOrDefault(w => w.IdStation == LohnStatList[0].IdStation).Name,
NWhichTime = this.NWhichTime[0].Id,
Period = Nomenclature.Period,
LohnStatList = LohnStatList,
CanEditTab = this.CanEditTabs
};
this.prevName = LohnStatList[0].Descript;
this.generalModel.PropertyChanged += GeneralModel_PropertyChanged;
this.BonusTabsList.Add(generalModel);
这是 GeneralTabVM 的构造函数:
public GeneralTabViewModel(GeneralTabDataModel model) : base(model)
{
this.IsLoadingData = true;
this.SelectBonusTypeCommand = new Command(this.OnSelectBonusTypeCommandExecute);
this.SelectStationCommand = new Command(this.OnSelectStationCommandExecute);
this.SelectedStationName = model.SelectedStationName;
this.Model = model;
this.Model.Descript.Trim();
this.LoadData();
this.Model.AcceptChanges();
this.Model.PropertyChanged += Model_PropertyChanged;
this.IsLoadingData = false;
}
解决方案
您使用的版本太旧(从 2015 年 11 月开始)。请至少升级到 5.x(2016 年 7 月发布)以获得一些可靠的答案。
即使你发现了一个错误,团队也不会在这么旧的版本中修复它。此外,该InterestedIn
功能已在 Catel 中删除,取而代之的是服务或MessageMediator
.
如果没有,如果这是一个选项,我建议使用不同类型的通信技术来解决问题(例如服务)。
推荐阅读
- c# - 如何使用 moq 和 nunit 对 grpc 方法进行单元测试?
- office-js - 使用 Excel JS 自定义函数文件在哪里调用 Office.initialize?
- html - 一个图像按钮导航到另一个站点 html/css
- java - 单击时找不到局部变量,调试器打开 Looper.java,应用程序死亡
- python - NLTK 路透社数据集未找到
- python - 来自 tika python 模块的警告消息使用 unpack 方法
- python - Django 测试:为多个类/文件重用“setUp”?
- r - 使用 Anaconda RStudio 在 MacOS 上安装 rgdal
- r - Shiny:根据 selectInput 选择动态分配 var 名称
- c++ - 如何创建一个空的全局类并在启动时实例化它?