Do I have to use CommandTarget? I thought any focused element would receive the Command

只谈情不闲聊 提交于 2019-11-29 05:05:40

You must set FocusManager.IsFocusScope to True.

<Button Content="Cut"  FocusManager.IsFocusScope="True"         
        Margin="12,195,0,0" 
        Height="23" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="75"                     
        Command="ApplicationCommands.Cut"/>

According to http://msdn.microsoft.com/en-us/magazine/cc785480.aspx, the reason for that is this:

If IsFocusScope="False", the command invoker looks for a command binding between its own location in the visual tree and the root of the visual tree.

If IsFocusScope="True", the command invoker also looks along the visual tree path from the root to the focus element for a command binding.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!