tags:

views:

343

answers:

2
 public MainWindow()
 {
    CommandManager.AddExecutedHandler(this, ExecuteHandler);
 }

 void ExecuteHandler(object sender, ExecutedRoutedEventArgs e)
 {
 }

Error 1 Argument 2: cannot convert from 'method group' to 'System.Delegate'

A: 

I guess there are multiple ExecuteHandler with different signatures. Just cast your handler to the version you want to have:

CommandManager.AddExecuteHandler(this, (Action<object,ExecutedRoutedEventArgs>)ExecuteHandler);
Achim
Got it - new the delegate type:CommandManager.AddExecutedHandler(this, new ExecutedRoutedEventHandler(ExecuteHandler));Actually even that wasn't necessary, my original code now seems to work fine.I didn't actually have two method definitions. I think this was maybe just a bug in VS where the error message was caused from some temporary object files. Weirdness.
Tim Lovell-Smith
A: 
CommandManager.AddExecutedHandler(this, (s, e) => ExecuteHandler(s, e));
Fábio Batista