Reputation: 3088
In XAML I have a ListBox MenuItem that for its Click="" method I want to reuse an existing method but which is already declared with (object sender, ExecutedRoutedEventArgs e) parameters.
Using it as so gives the following error: Error CS1503 Argument 2: cannot convert from 'System.Windows.RoutedEventArgs' to 'System.Windows.Input.ExecutedRoutedEventArgs'
Is it possible to convert ExecutedRoutedEventArgs to RoutedEventArgs for it to work? or any other way?
Upvotes: 1
Views: 1343
Reputation: 169400
You can't change the signature of the event delegate - a click event handler only accepts a RoutedEventArgs
and nothing else - but you can move the code from the existing event handler into a method that you can call from any event handlers, e.g.:
private void OnClick(object sender, ExecutedRoutedEventArgs e)
{
YourMethod();
}
private void OnClick1(object sender, RoutedEventArgs e)
{
YourMethod();
}
private void YourMethod()
{
//your common logic...
}
Upvotes: 1