Consider the following example with a menu and a button:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="Paste" Command="ApplicationCommands.Paste" />
</Menu>
<Button Command="ApplicationCommands.Paste">Paste</Button>
<TextBox>Content</TextBox>
<TextBox>Content2</TextBox>
</DockPanel>
</Window>
When I put keyboard focus in one of the text boxes, the TextBox declares that it can handle ApplicationCommands.Paste
, and so I expect the button and the menu item to enable themselves. What I get instead is that the menu item enables itself, and the button does not. (The button doesn't appear to be "listening" to the TextBox
' CommandBinding
)
What's going on here, and is there any way I can work around this?
EDIT: I did find this question --> WPF routed command enabling works with menu but not with a button <-- but this is not suitable in this case. The button should not be keyboard focusable, and setting it as a focus scope makes it focusable. I can't bind the source, because the actual source needs to be controlled by keyboard focus.