2

我正在玩RoutedCommand,我在寻找如何传递参数以便我的Executed方法将它包含在 e.Parameter 时遇到问题?

我的路由命令:

public static readonly RoutedCommand Foo = new RoutedCommand();

用法:

menuItem.Command = Commands.Foo;

执行:

private void Foo_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            object parameter = e.Parameter; // this is always null
        }
4

2 回答 2

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";
于 2011-11-07T19:42:15.193 回答
1

You should use MenuItem.CommandParameter.

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

于 2011-11-07T19:39:33.680 回答