Skip to content

Instantly share code, notes, and snippets.

@SmashBrando
Created August 13, 2021 15:46
Show Gist options
  • Save SmashBrando/7821faee6eedfa916486d097bc18a813 to your computer and use it in GitHub Desktop.
Save SmashBrando/7821faee6eedfa916486d097bc18a813 to your computer and use it in GitHub Desktop.
// Get the control's Type
Type controlViewType = ((UIElement)control).GetType();
// Dig out the undocumented (yes, I know, it's risky) EventHandlerStore
// from the control's Type
PropertyInfo EventHandlersStoreType =
controlViewType.GetProperty("EventHandlersStore",
BindingFlags.Instance | BindingFlags.NonPublic);
// Get the actual "value" of the store, not just the reflected PropertyInfo
Object EventHandlersStore = EventHandlersStoreType.GetValue(tree, null);
var miGetRoutedEventHandlers = EventHandlersStore.GetType().GetMethod("GetRoutedEventHandlers", BindingFlags.Public | BindingFlags.Instance);
RoutedEventHandlerInfo[] res = (RoutedEventHandlerInfo[])miGetRoutedEventHandlers.Invoke(EventHandlersStore, new object[] { CheckedTreeViewItem.CheckedEvent });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment