streamdown
streamdown

Reputation: 390

Catel Cancel button in DataWindow

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

Upvotes: 3

Views: 258

Answers (2)

Florian
Florian

Reputation: 390

faced exactly the same problem with an ObservableCollection, simply resolved it by adding [Serializable] Attribute to the model class

[Serializable]
public class ProgramDataModel:ValidatableModelBase
{
}

Upvotes: 0

Geert van Horrik
Geert van Horrik

Reputation: 5724

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.

Upvotes: 0

Related Questions