It seems that the XAML in MVVM pattern has difficulty to pop-up a Messageboxes. My client insists that the validation labels and colors are not good for them. They still want a messagebox. How can do it?
I know I can pop-up messageboxes in the view-model, but it violates the whole purpose for the view-model. I can also raise a error, and pop-up a messagebox in some exception handlers, but the messagebox is not an exception. It is part of the normal program flow.
Is there a good way to do it in XAML? My client likes messageboxes. She does not care about the MVVM pattern, she never had any quality problem before using MVVM and unit test. But now, she can not even get her messageboxes, so she is not very happy.
Open Settings . Click Apps. In the list of apps, click Messages.
Commands are an implementation of the ICommand interface that is part of the . NET Framework. This interface is used a lot in MVVM applications, but it is useful not only in XAML-based apps.
Introduction to MVVM C# MVVM (Model-View-ViewModel) C# is the technique of generating the client applications which control the core features of the WPF platform, enabling the ease of unit testing of app functionality. MVVM (Model-View-ViewModel) is an architectural pattern that signifies three different components.
One possibilty is to use an interface for the messagebox like
public interface IMessageBoxProvider
{
MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult);
}
and a wrapper class that implements this interface and uses a normal or custom messagebox. In the viewmodel you can then use like this
private IMessageBoxProvider MessageBox { get; set; }
where MessageBox is the wrapper class. So now you have decoupled the actual messagebox and so you are able to to unit testing and what not.
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