gpt4 book ai didi

wpf - LoadedEvent 的路由事件类处理程序不适用于大多数类

转载 作者:行者123 更新时间:2023-12-05 00:33:52 24 4
gpt4 key购买 nike

我正在尝试为所有 Loaded 事件注册处理程序:

EventManager.RegisterClassHandler(typeof(UIElement), FrameworkElement.LoadedEvent, new RoutedEventHandler(OnRoutedEvent), true);
EventManager.RegisterClassHandler(typeof(ContentElement), FrameworkContentElement.LoadedEvent, new RoutedEventHandler(OnRoutedEvent), true);
EventManager.RegisterClassHandler(typeof(UIElement), FrameworkElement.UnloadedEvent, new RoutedEventHandler(OnRoutedEvent), true);
EventManager.RegisterClassHandler(typeof(ContentElement), FrameworkContentElement.UnloadedEvent, new RoutedEventHandler(OnRoutedEvent), true);

不幸的是,我的处理程序只为 Window 和 DatePicker 的后代调用。它不适用于任何其他类型。

谁能解释这种行为?这是一个 bug ,可悲的是他们选择忽略它。

是否有其他方法可以通知 application/window 中的任何新元素?

最佳答案

也许你可以定义一个 AttachedProperty/Behavior<T>使用 FrameworkPropertyMetadataOptions.Inherits ,然后在您的根元素上指定它,并在行为 Hook 中 Loaded/Unloaded每个实例上的事件

关于wpf - LoadedEvent 的路由事件类处理程序不适用于大多数类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11455800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com