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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -