Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf Can';t将菜单项中的命令绑定到命令绑定_Wpf_Menuitem_Commandbinding - Fatal编程技术网

Wpf Can';t将菜单项中的命令绑定到命令绑定

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

我有以下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" 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}"