父更改事件上的 WPF UserControl [英] WPF UserControl on parent changed event

查看:25
本文介绍了父更改事件上的 WPF UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中的主窗口可以包含其他停靠/附加窗口.现在,当我的用户控件加载时,我使用 Window.GetWindow 获取其父控件.这将返回对主窗口的引用,这很好.但是,当我取消停靠/分离用户控件所在的子窗口时,父窗口会发生变化.

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.

用户控件需要监听许多父窗口事件.我找不到在父控件更改时通知用户控件的任何方法.System.Windows.Controls.UserControl 似乎不存在 ParentChanged/OnParentChanged.

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?

谢谢.

推荐答案

也许 Loaded 和 Unloaded 事件正是您所需要的.当父级发生变化时也应该调用它们,但我不确定这一点.

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.

这篇关于父更改事件上的 WPF UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆