What use has RoutedCommand' class constructor ownertype argument?

后端 未结 2 1297
[愿得一人]
[愿得一人] 2020-12-19 02:03

The constructor of the RoutedCommand has \"owner type\" as a last argument. What is its significance? When it is used?

MSDN documentation gives completely no clue a

2条回答
  •  长情又很酷
    2020-12-19 02:33

    The source for RoutedCommand shows that the type becomes the OwnerType property. This property is queried ultimately by the following private method when getting InputGestures. So it looks as though this type is being used to lookup a (hard-coded) set of Commands based on the type that created the 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();
    }
    

提交回复
热议问题