简体   繁体   中英

Problems with Catel in WPF, InterestedIn ViewModel reloading

So I have a viewmodel called NewBonusCalculationViewModel. This viewmodel is interested in a few other viewmodels which serve as tabs in NewBonusCalculationViewModel.

One of the tabs that the NewBonusCalculationViewModel is interested in is called GeneralTabVM. This GeneralTabVM has a data model called GeneralTabDataModel and the properties from the datamodel are mapped with the GneralTabVM(ViewModelToModel).

In the GeneralTabDataModel i have a property called StartingTime and when I open the NewBonusCalculationViewModel page and hit the X button(without making any changes) the viewmodel kind of resets the values of the StartingTime property and this raises IsModelDirtyChanges and I get the question "Do you want to save changes?".

I can not find what causes the viewmodel to reset or reload. I am using Catel 4.4.

I tried removing the mapping, the interestedIn, even removing the property StartingTime(and using Model.StartingTime) but nothing seems to work.

This is how I load the GeneralTab props form NewBonusCalcVieModel:

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);

This is the constructor for the 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;

}

The version you are using is too old (from November 2015). Please upgrade to at least 5.x (release in July 2016) to get some solid answers.

Even if you found a bug, the team will not fix it in such an old version. Also, the InterestedIn feature has been dropped in Catel in favor of services or the MessageMediator .

If none if this is an option, I recommend to use a different kind of communication tech to work around the problem (eg a service).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM