2

I'm playing around with RoutedCommand, and I'm having an issue with finding how can I pass a parameter so that my Executed method will have it in e.Parameter ?

My RoutedCommand:

public static readonly RoutedCommand Foo = new RoutedCommand();

Usage:

menuItem.Command = Commands.Foo;

Executed:

private void Foo_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            object parameter = e.Parameter; // this is always null
        }
pguzewicz
  • 304
  • 2
  • 13

2 Answers2

8

You're parameter is always null because you never set it anywhere

You can set it using the CommandParameter property

menuItem.Command = Commands.Foo;
menuItem.CommandParameter = "Bar";
Rachel
  • 130,264
  • 66
  • 304
  • 490
1

You should use MenuItem.CommandParameter.

For example, you could set binding to some property, from which parameter is delivered.

Alex Zhevzhik
  • 3,347
  • 19
  • 19