2011-04-14 77 views
4

這裏一個額外的參數的ICommand的成員的定義:http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.execute.aspx接口實現具有在功能

簽名是:

 

void Execute(
    Object parameter 
) 
 

它是由的RoutedCommand具有以下簽名實現(http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.execute.aspx) :

 

public void Execute(
    Object parameter, 
    IInputElement target 
) 
 

的RoutedCommand如何可以在成員functi一個額外的參數(IInputElement)實現的ICommand上?

回答

9

它使用explicit interface implementation來「隱藏」採用單個參數的ICommand.Execute方法。採用兩個參數Execute方法不是執行ICommand.Execute

public class RoutedCommand : ICommand 
{ 
    public void Execute(object parameter, IInputElement target) 
    { 
     // ... 
    } 

    // explicit interface implementation of ICommand.Execute 
    void ICommand.Execute(object parameter) 
    { 
     // ... 
    } 
} 
+0

感謝您的回答。我也很驚訝,但我的查詢也在這裏解決了。 – Snesh 2015-11-03 04:28:48

1

ICommand.Execute()接口方法是顯式實現的。 Docs are here