It’s a pretty straight forward question.
I have my main window in a WPF project, which I want it to open a specific window with dependency properties on it. Now the first time around it doesn’t complain one bit about it. But subsequent attempts to open the window gives me an error about the dependency property already being registered, and that it can’t register it again.
I tried keeping the window as a global variable, but then I get an obvious error about trying to re-open an already closed window.
So what would I need to do to be able to re-open the window, and not be stopped in my tracks because it tries to re-register the properties?
My main MO here is to recreate the window each time it needs to be opened (standard dialog/window procedure).
I register the properties like this:
public partial class MessageAndWaitingWindow : Window
{
public DependencyProperty CustomMessageProperty =
DependencyProperty.Register("CustomMessage", typeof(string), typeof(MessageAndWaitingWindow));
public DependencyProperty WaitingProperty =
DependencyProperty.Register("Waiting", typeof(string), typeof(MessageAndWaitingWindow));
public DependencyProperty WaitingPanelVisibilityProperty =
DependencyProperty.Register("WaitingPanelVisibility", typeof(Visibility), typeof(MessageAndWaitingWindow));
// Rest of the class.
}
Sounds like your either registering your
DependencyPropertyin the instance constructor or have theDependencyPropertydeclared non-static.Make sure you define your
DependencyPropertyfield as static and either register it in the static constructor or register it inline.