Flack
Flack

Reputation: 5899

WPF UserControl on parent changed event

I have an app where I have a main window that can contain other docked/attached windows. Right now, when my user control loads I get its parent using Window.GetWindow. This returns a reference to the main window, which is fine. However, when I undock/detach the child window that the user control is on, the parent changes.

There are a number of parent window events that the user control needs to listen for. I couldn't find any way for the user control to be notified when the parent changes. It looks like ParentChanged/OnParentChanged do not exist for System.Windows.Controls.UserControl.

Is there any way my user control can be notified when its parent changes?

Thanks.

Upvotes: 4

Views: 3165

Answers (2)

Aalganim
Aalganim

Reputation: 1

Use protected override sub onparentchange

 check is parent not nothing

If true you can adhandle parent_onmouseup

Addressof event you created

Upvotes: -3

jbe
jbe

Reputation: 7031

Maybe the Loaded and Unloaded events are what you need. They should also be called when the parent changes but I'm not sure about this.

Upvotes: 5

Related Questions