You can also do this using an event. Although you need as 3 lines of code in your view code (some MVVM purists don't like this);
In your view model, you create an event that the view can subscribe to:
public event CloseEventHandler Closing; public delegate void CloseEventHandler(); private void RaiseClose() { if (Closing != null) Closing(); }
In your view, you are subscribing to an event after your initializecomponent method, as shown below:
public View { *
You simply call RaiseClose () when you are ready to close the view from the ViewModel.
You can even use this method to send a message to a view from view mode.
The event can be placed in the interface to avoid direct dependence of the view on the viewmodel.
falopsy Aug 11 '17 at 11:38 on 2017-08-11 11:38
source share