Gurebu Bokofu Gurebu Bokofu - 1 year ago 126
C# Question

WPF: Meaning of the first two "same" arguments in RoutedUICommand()

In all examples that I checked, first two arguments of

are same string, e.g.

private static RoutedUICommand add = new RoutedUICommand("Add", "Add", typeof(CommandLibrary));

What the difference between them?

Answer Source

You can always check the metadata for the meaning by pressing F12 with your I-beam on the class while using Visual Studio.
Anyway, with the constructor RoutedUICommand(String, String, Type): the first string is a descriptive text, the second is the name, and the third is the owner type. It doesn't have to be the same.
Consider this example here:

public static RoutedCommand GreetUserCommand = new RoutedUICommand("Howdy! Just to say hello, nothing else.", "GreetUser", typeof(MainWindow));

and usage of the view:

    <CommandBinding Command="{x:Static loc:MainWindow.GreetUserCommand}" 
                    CanExecute="GreetUser_CanExecute" Executed="GreetUser_Executed"/>

        <MenuItem Command="{x:Static loc:MainWindow.GreetUserCommand}"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download