RoutedCommand的源代碼顯示該類型成爲OwnerType屬性。獲取InputGestures時,最終通過以下私有方法查詢此屬性。因此,看起來好像這種類型正在用來查找基於創建RoutedCommand的類型的(硬編碼的)一組命令。
private InputGestureCollection GetInputGestures()
{
if (this.OwnerType == typeof(ApplicationCommands))
{
return ApplicationCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(NavigationCommands))
{
return NavigationCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(MediaCommands))
{
return MediaCommands.LoadDefaultGestureFromResource(this._commandId);
}
if (this.OwnerType == typeof(ComponentCommands))
{
return ComponentCommands.LoadDefaultGestureFromResource(this._commandId);
}
return new InputGestureCollection();
}
有人可以解釋爲什麼? – 2009-05-30 19:21:39
也許只是「因爲」。這是API設計的理由。 * blech * – 2009-06-08 14:00:32