2011-11-07 38 views
2

我與玩弄的RoutedCommand,和我在與發現的問題我怎麼能傳遞一個參數,使我伏法方法有它在e.Parameter?的RoutedCommand與參數

我的RoutedCommand:

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 
     } 

回答

8

你參數始終是null因爲你永遠不設置任何地方

你可以把它用CommandParameter財產

menuItem.Command = Commands.Foo; 
menuItem.CommandParameter = "Bar"; 
+0

衛生署訂!忽略了這一個......無論如何感謝你的快速回答! – pguzewicz