Then I modify "ProductName" and press "Cancel" button property is reset to passed parameter. But if i modify ProgramIds (add, or delete) and press "Cancel" button collection no set to passed. Why?
I have in ViewModel:
[Model]
[Catel.Fody.Expose("ProductName")]
[Catel.Fody.Expose("ProgramIds")]
Public ProgramDataModel DataModel
{
get { return GetValue<ProgramDataModel>(DataModelProperty); }
set { SetValue(DataModelProperty, value); }
}
In Model:
public string ProductName
{
get { return GetValue<string>(ProductNameProperty); }
set { SetValue(ProductNameProperty, value); }
}
public static readonly PropertyData ProductNameProperty = RegisterProperty(nameof(ProductName), typeof(string));
public ObservableCollection<ProgramIDModel> ProgramIds
{
get { return GetValue<ObservableCollection<ProgramIDModel>>(ProgramIdsProperty); }
set { SetValue(ProgramIdsProperty, value); }
}
public static readonly PropertyData ProgramIdsProperty = RegisterProperty(nameof(ProgramIds), typeof(ObservableCollection<ProgramIDModel>));
In MainViewModel:
var viewModel = new ProductWindowViewModel(DataViewModel);
await _uiVisualizerService.ShowDialogAsync(viewModel);
Catel uses IEditableObject
in order to restore the state when the user hits cancel. Because you are using a collection of ids, Catel might have some issues resetting the collection.
Please report this issue (with repro) at the official issue tracker.
As a workaround for now, you can override the CancelAsync
method and revert the collection there yourself. Or as an alternative you can use a cloned collection in the VM and only replace the items in SaveAsync
.