add a check with MessageBox when DataGrid is changed

前端 未结 3 1776
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 02:58

I have a desktop app already released (so I\'d appreciate an answer that keeps the changes and regression tests at a minimum) and I need to add a consistency check Can

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 03:01

    What I've done till now is

    against MVVM, because I've put the alert in the Model

    The solution from @Tesseract, subclassing ObservableCollection and subscribing RemoveItem is already MVVM oriented.

    What is still missing is a correct, modern way to send the alert from the ViewModel. This is where Mahapps approach would be helpful.

    • Use an attached property in your Window to register your view model with the dialog sub-system.

    In your XAML

    Dialog:DialogParticipation.Register="{Binding}"
    

    where the attached property DialogPartecipation will keep track of the views through a dictionary

    public static class DialogParticipation
    {
        private static readonly IDictionary ContextRegistrationIndex = new Dictionary
    • You can instantiate DialogCoordinator directly or inject the interface IDialogCoordinator into their view model

    The DialogCoordinator will match the ViewModel to the View

    public class DialogCoordinator : IDialogCoordinator
    {
        public static readonly IDialogCoordinator Instance = new DialogCoordinator();
    

    through the above said attached property (the context being the view model)

    var association = DialogParticipation.GetAssociation(context);
    

    and display the dialog, invoking the appropriate method on the retrieved view: this is how, if you have multiple windows open, the dialog will display on the correct window.

提交回复
热议问题