在下面的示例中,当文本获得焦点而不是按钮时,菜单被启用。我只用按钮和文本框试过了,但行为是一样的。
<Window x:Class="WpfPopup.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 Command="ApplicationCommands.Paste" />
</Menu>
<TextBox BorderBrush="Black" BorderThickness="2" Margin="25" TextWrapping="Wrap" x:Name="text1" Height="58" Width="203" >
The MenuItem will not be enabled until
this TextBox gets keyboard focus
</TextBox>
<Button Content="Button" Height="23" Name="button1" Width="93" Command="ApplicationCommands.Paste" />
</DockPanel>