(I’m trying to create my own custom MSGBOX from wpf…)
How do I show another WPF Window without having this kind of code
WpfWindow w = new WpfWindow();
w.SetBox("hellow world");
w.ShowDialog();
however i kind of found a way to lessen the CODE but i still need to create another instance (which is a waste of resources)
new WpfWindow().ShowBox("hellow world");
the ShowBox(string msg) Method:
public bool? ShowBox()
{
SetBox(msg);
return w.ShowDialog();
}
I want to get rid of that “new” code snippet (if that’s what you call it)
so…in conclusion…I wanted to know how to make a Static WPF Window…
You can simply wrap your code in a static method in your class:
You then call it like this:
You may object to the fact that a new instance of the window is created on each call but I don’t think you can avoid that. You are using
ShowDialogto show a modal dialog and for this dialog to return control to your code it has to be closed. A closed window cannot be reopened and you have to create a new instance each time. It shouldn’t be a problem though.