c# - How to close parent windows using WPF User Control -
assume have 2 wpf windows: window_one , window_two.
- window_one has 1 button. clicking button opens window_two.
- window_two contains user control.
- this user control has 1 button closes window_two.
how can achieve scenario?
inside custom control you've created. can access parent window within button event click.
either using visual tree:
var mywindow = (window)visualparent.getselfandancestors().firstordefault(a => window); mywindow.close();
or simply:
var mywindow = window.getwindow(this); mywindow.close();
of course, other option create custom event says "mybuttonclicked" , have window hosts usercontrol listen event , when event fired, close current window.
cheers!
Comments
Post a Comment