Inconsistency in WPF command routing behavior depending on the UI focus state

后端 未结 3 570
暖寄归人
暖寄归人 2020-12-31 04:05

I have a RoutedUICommand command which can be fired in two different ways:

  • directly via ICommand.Execute upon a button click event;
3条回答
  •  爱一瞬间的悲伤
    2020-12-31 04:44

    JoeGaggler, a colleague of mine, has apparently found the reason for this behavior:

    I think I found it using reflector: if the command target is null (i.e. keyboard focus is null), then the ICommandSource uses itself (not the window) as the command target, which ultimately hits the CommandBinding for the window (this is why the declarative binding works).

    I'm making this answer a community wiki, so I don't get credits for his research.

提交回复
热议问题