Takeshi Tokugawa YD
Takeshi Tokugawa YD

Reputation: 979

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

In all examples that I checked, first two arguments of RoutedUICommand() are same string, e.g.

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

What the difference between them?

Upvotes: 1

Views: 68

Answers (1)

Lam Le
Lam Le

Reputation: 1839

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:

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

<Window.ContextMenu>
    <ContextMenu>
        <MenuItem Command="{x:Static loc:MainWindow.GreetUserCommand}"/>
    </ContextMenu>
</Window.ContextMenu>

Upvotes: 1

Related Questions