Good or bad practice for Dialogs in wpf with MVVM?

前端 未结 3 1715
孤城傲影
孤城傲影 2020-11-22 03:54

I lately had the problem of creating add and edit dialogs for my wpf app.

All I want to do in my code was something like this. (I mostly use viewmodel first approach

3条回答
  •  遥遥无期
    2020-11-22 04:33

    This is a good approach and I used similar ones in the past. Go for it!

    One minor thing I'd definitely do is make the event receive a boolean for when you need to set "false" in the DialogResult.

    event EventHandler RequestCloseDialog;
    

    and the EventArgs class:

    public class RequestCloseEventArgs : EventArgs
    {
        public RequestCloseEventArgs(bool dialogResult)
        {
            this.DialogResult = dialogResult;
        }
    
        public bool DialogResult { get; private set; }
    }
    

提交回复
热议问题