I'm trying to register handler for all Loaded events:

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);

Unfortunately my handler is only called for Window and descendants of DatePicker. It does not work for any other type.

Can anyone explain this behavior ? It's a bug, sadly they've chosen to ignore it.

Is there some other way to be notified about any new element in application/window ?

有帮助吗?

解决方案

Perhaps you could define an AttachedProperty/Behavior<T> that uses FrameworkPropertyMetadataOptions.Inherits, and then specify it on your root element, and in the behaviour hook the Loaded/Unloaded events on each instance

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top