Search code examples
wpf.net-6.0routedeventargs

Runtime type of CheckBox RoutedEventArgs.UserInitiated


Related to this answer, how does one find the runtime type of a property that is visible in the debugger? I'd like to access UserInitiated.

(I now also secondarily want to know what this property means, since even when clicking manually, UserInitiated returns false. There doesn't seem to be meaningful documentation online.)

debugger for RoutedEventArgs

This from-scratch scenario is a WPF .NET 6 project with a Check Box control and a CheckBox_Checked event handler.

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    { }

The original type of RoutedEventArgs e is unclear. Additional properties, such as e.UserInitiated available in the debugger won't compile.

Even in the Locals window, the type is still marked System.Windows.RoutedEventArgs, which is ostensibly correct. But RoutedEventArgs doesn't contain the property UserInitiated. Even trying different types, looking for questions and documentation online, using GetType(), and typecasting to related types hasn't yielded a useful answer.

The purpose is to differentiate between when code updates a check box vs. a user manually clicking on the check box.


Solution

  • As an answer to the basic problem, inspired by this answer, it's possible to make the difference between a user checking a box and the code by using the check box's Click event.

    This doesn't so much answer the UserInitiated question as practically solve the problem at hand.