Wpf Can';t将菜单项中的命令绑定到命令绑定
我有以下xaml:Wpf Can';t将菜单项中的命令绑定到命令绑定,wpf,menuitem,commandbinding,Wpf,Menuitem,Commandbinding,我有以下xaml: <Window x:Class="Isolator.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Isolator" Height="394" Width="486" Background="Black" WindowSt
<Window x:Class="Isolator.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Isolator" Height="394" Width="486" Background="Black" WindowStyle="None" WindowState="Maximized">
<Window.CommandBindings>
<CommandBinding Command="Close" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"/>
</Window.CommandBindings>
<Window.ContextMenu>
<ContextMenu>
<MenuItem Header="Stop" Name="StopMenuItem" Click="StopMenuItem_Click" />
<MenuItem Header="Close" Command="Close"/>
</ContextMenu>
</Window.ContextMenu>
<Grid Loaded="Grid_Loaded">
</Grid>
</Window>
“关闭”菜单项指定应使用“关闭”命令。Close命令绑定指定应为CanExecute调用CommandBinding_CanExecute,但从不调用CommandBinding_CanExecute。关闭菜单项始终处于禁用状态
我假设绑定没有发生。有人能解释为什么吗
如果它与上下文菜单不在可视化树中有关,您如何解决它?此语句
Command=“Close”
没有任何作用。您的意思是命令是字符串“Close”。这就是它不起作用的原因
如果在窗口中定义了关闭命令实例,请使用command=“{Binding Close}”
。或者,如果您正在使用ApplicationCommand.Close,则
Command="{x:Static ApplicationCommands.Close}"