Prevent a user control from closing WPF C# -


i have application in user fills out form, if user doesn't press save , loads control/button need stop user leaving , destroying user control. there isn't closing event on user control. tried unloaded has disconnected visual tree. have have create variables throughout check? there event use situation?

update

so have 1 window application , many user controls load in grid, example if client press contact new contact user control occur child of window. if user hasn't pressed save want user control not removed , prompt message. hope explains bit more.

so, far understand question, swap user controls in main window's code. don't want 1 of controls swapped if inputs incomplete.

you have code yourself. have method following in main window's code switch usercontrol:

private void swapview(usercontrol newview) {     // remove old user control     ...      // show new user control     ... } 

what need flag in usercontrol derived class indicates whether possible swap or not. best, define interface this:

public interface iview {     bool canclose(); } 

and have all your usercontrols implement it:

public class mycontrol : usercontrol, iview {     ...      public bool canclose()     {         // determine whether control can closed         bool result = ...         return result;     }      ... } 

then can change above method to:

private void swapview(iview newview) {     // current view     iview currentview = ...      // check whether can closed     if (!currentview.canclose())     {         ...         return;     }      // remove old user control     ...      // show new user control     ... } 

you can extend message shown user providing reason not being able change views.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -