WPF assumes MVVM for most things. e.g. using a the wpf tree control without MVVM will have you tearing your hair out within a day.. MVVM just makes things simpler and testable. This could answer some of the questions: wintellect.com/CS/blogs/jlikness/archive/2010/04/14/….
MVVM Done Right is Slow In a large application, you might need to loop through the data multiple times to make sure it has all recalculated correctly. If you just use the framework and let the framework deal with your sloppy code, this can make the system incredibly slow.
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<RequestCloseEventArgs> RequestCloseDialog;
and the EventArgs class:
public class RequestCloseEventArgs : EventArgs
{
public RequestCloseEventArgs(bool dialogResult)
{
this.DialogResult = dialogResult;
}
public bool DialogResult { get; private set; }
}
I've been using an almost identical approach for several months now, and I'm very happy with it (i.e. I haven't yet felt the urge to rewrite it completely...)
In my implementation, I use a IDialogViewModel
that exposes things such as the title, the standad buttons to show (in order to have a consistent apparence across all dialogs), a RequestClose
event, and a few other things to be able to control the window size and behavior
If you are talking about dialogue windows and not just about the pop-up message boxes, please consider my approach below. The key points are:
Module Controller
into the constructor of each ViewModel
(you can use injection).Module Controller
has public/internal methods for creating dialogue windows (just creating, without returning a result). Hence to open a dialogue window in ViewModel
I write: controller.OpenDialogEntity(bla, bla...)
Pros:
Module Controller
is a simple way to avoid strong references and still allows to use mock-ups for testing.Cons:
<T>
where T
is enumeration of entities (or for simplicity it can be type of ViewModel).Module Controller
can be overwhelmed by methods for creating windows. In this case it's better to split it up in several modules.P.S. I have been using this approach for quite a long time now and ready to defend its eligibility in comments and provide some examples if required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With