The interface implementation has an additional argument in the function

Here is the ICommand member definition: http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.execute.aspx

Signature:

void Execute( Object parameter ) 

It is implemented by RoutedCommand with the following signature ( http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.execute.aspx ):

 public void Execute( Object parameter, IInputElement target )
public void Execute( Object parameter, IInputElement target ) 

How can RoutedCommand implement ICommand with an additional argument (IInputElement) in a member function?

+4
source share
2 answers

It uses an explicit implementation of the interface to β€œhide” ICommand.Execute , which takes a single parameter. The Execute method, which takes two parameters, is not an implementation of ICommand.Execute .

 public class RoutedCommand : ICommand { public void Execute(object parameter, IInputElement target) { // ... } // explicit interface implementation of ICommand.Execute void ICommand.Execute(object parameter) { // ... } } 
+9
source

The ICommand.Execute () interface method is implemented explicitly. Docs are here .

+1
source

Source: https://habr.com/ru/post/1348064/


All Articles