.net - Callback from Dialog window to Main window -
.net - Callback from Dialog window to Main window -
i'm developing wpf mvvm application create utilize of mvvmlighttoolkit 3rd party helper.my scenarion follows:
i have main window , while closing main window, have show new dialog window(save changes dialog window) confirm user that, whether has save changes made in application state file or not. how can handle scenario in mvvm?. showing new window, i'm making utilize of mvvmlight messenger class.in case, i'm opening save changes dialog window main window code behind.i need phone call main view model based on selected user option(save,save/exit,cancel) save changes dialog window , based on have check whether have close main window or not. best mvvm approach handle scenario?
just pass messages from/ viewmodel.
view:
class="lang-cs prettyprint-override">private void window_closing(object sender, canceleventargs e) { messenger.default.send(new windowrequestsclosingmessage( this, null, result => { if (!result) e.cancel = true; }); }
viewmodel:
class="lang-cs prettyprint-override">messenger.default.register<windowrequestsclosingmessage>( this, msg => { // logic before close if (canclose) msg.execute(true); else msg.execute(false); });
message:
class="lang-cs prettyprint-override">public class windowrequestsclosingmessage: notificationmessageaction<bool> { public windowrequestsclosingmessage(string notification, action<bool> callback) : base(notification, callback) { } public windowrequestsclosingmessage(object sender, string notification, action<bool> callback) : base(sender, notification, callback) { } public windowrequestsclosingmessage(object sender, object target, string notification, action<bool> callback) : base(sender, target, notification, callback) { } }
mvvm light's notificationmessageaction<tresult> allows pass message , result of tresult type. pass tresult requester, phone call execute()
example.
.net wpf mvvm callback mvvm-light
Comments
Post a Comment