首页 > 解决方案 > 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;

}

标签: c#wpfcatel

解决方案


您使用的版本太旧(从 2015 年 11 月开始)。请至少升级到 5.x(2016 年 7 月发布)以获得一些可靠的答案。

即使你发现了一个错误,团队也不会在这么旧的版本中修复它。此外,该InterestedIn功能已在 Catel 中删除,取而代之的是服务或MessageMediator.

如果没有,如果这是一个选项,我建议使用不同类型的通信技术来解决问题(例如服务)。


推荐阅读