public static void AddEventHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler) { UIElement uiElement = element as UIElement; if (uiElement != null) { uiElement.AddHandler(routedEvent, handler); } else { ContentElement contentElement = element as ContentElement; if (contentElement != null) { contentElement.AddHandler(routedEvent, handler); } else { UIElement3D uiElement3d = element as UIElement3D; if (uiElement3d != null) { uiElement3d.AddHandler(routedEvent, handler); } } } }
public static void AddHandler(this DependencyObject element, RoutedEvent routedEvent, Delegate handler) { Debug.Assert(element != null, "Element must not be null"); Debug.Assert(routedEvent != null, "RoutedEvent must not be null"); UIElement uiElement = element as UIElement; if (uiElement != null) { uiElement.AddHandler(routedEvent, handler); } else { ContentElement contentElement = element as ContentElement; if (contentElement != null) { contentElement.AddHandler(routedEvent, handler); } else { UIElement3D uiElement3D = element as UIElement3D; if (uiElement3D != null) { uiElement3D.AddHandler(routedEvent, handler); } } } }