Reputation:
I have main wpf window, in this window I create new slave windows and add in dictionary. It is possible, after closing the slave window, it showed once again.
public class MainWindow:Window
{
private dictionary<string, SlaveWindow> _winDic= new dictionary<string, SlaveWindow>();
public void SomeMethod()
{
var mySlaveWindow = new SlaveWindow();
//add to dictionary
_winDic.Add("mySlaveWindow",w);
//close slave window w
//show
_winDic[mySlaveWindow].Show();
}
}
Upvotes: 0
Views: 521
Reputation: 84647
This following way of doing this is taken from this msdn page.
Subscribe to the Closing event for the Window and add this in code behind.
private bool m_close = false;
// Shadow Window.Close to make sure we bypass the Hide call in
// the Closing event handler
public new void Close()
{
m_close = true;
base.Close();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
// If Close() was called, close the window (instead of hiding it)
if (m_close == true)
{
return;
}
// Hide the window (instead of closing it)
e.Cancel = true;
this.Hide();
}
This will make sure your Window finally closes and is not left hanging.
Upvotes: 1
Reputation: 14537
You'll need to hide the window rather than closing it.
If you call Hide()
, the window will vanish like it would when you call Close()
but you'll be able to reshow it later by calling Show()
again.
Upvotes: 0