Reusing Window Objects

Quick question:

I have a XAML/C# Window object which is a WPF dialog box. When I want to show the dialog I call the ShowDialog function. Then when the user presses Ok, Cancel, Escape, or presses the Close Button the window disappears, and ShowDialog returns the dialog result. Is it then possible to resuse this object to show the dialog more times, without creating a new fresh object. It seems that once Close has been called, the window is in "dead" state.

The reason I ask is because doing this will be a simple way to persist the user's dialog choices - I don't care about WPF's state, I just care about maintaing my objects which the XAML binds to. Hence I don't want to discard the object.

Can I do this


Answer this question

Reusing Window Objects

  • Coombsey

    That's a good answer. Thank you.

  • Lucky_123

    Once the Window has been closed, it cannot be reused. The way to reuse a Window is to hide and re-show it (you can hide a Window by setting Window.Visibility=Visibility.Hidden, or by calling Window.Hide()).

    Hope this helps,
    Lauren [MS]



  • Reusing Window Objects