WPF UserControl on Parent Modified Event

I have an application where I have a main window that may contain other docked / docked windows. Right now, when my user control loads, I get its parent element using Window.GetWindow. This returns a link to the main window, and this is normal. However, when I detach / detach the child window in which the user control is enabled, the parent element changes.

There are several parent window events that the user control should listen on. I could not find any way for the user control to be notified when the parent element changes. It seems that ParentChanged / OnParentChanged does not exist for System.Windows.Controls.UserControl.

Is there a way that my user control can be notified when the parent element changes?

Thank.

+3
source share
2 answers

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

+5
source

Use secure override sub onparentchange

 check is parent not nothing

true, adhandle parent_onmouseup

-2

Source: https://habr.com/ru/post/1774403/


All Articles