Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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
C# WPF-名称不为';名称空间中不存在_C#_Wpf_Namespaces_Undefined - Fatal编程技术网

C# WPF-名称不为';名称空间中不存在

C# WPF-名称不为';名称空间中不存在,c#,wpf,namespaces,undefined,C#,Wpf,Namespaces,Undefined,我在尝试在WPF中实现一些自定义绑定时遇到了名称空间问题。我收到错误“名称”CustomCommands“不存在于名称空间”clr namespace:GraphicsBook;assembly=Testbed2D” 在我的XAML中,我有: <Window x:Class="GraphicsBook.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sche

我在尝试在WPF中实现一些自定义绑定时遇到了名称空间问题。我收到错误“名称”CustomCommands“不存在于名称空间”clr namespace:GraphicsBook;assembly=Testbed2D”

在我的XAML中,我有:

<Window x:Class="GraphicsBook.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:k="clr-namespace:GraphicsBook;assembly=Testbed2D"
Title="Window1"

 <Window.CommandBindings>
    <CommandBinding Command="k:CustomCommands.AddCircle" CanExecute="AddCircleCommand_CanExecute" Executed="AddCircleCommand_Executed"></CommandBinding>
</Window.CommandBindings>

<Menu>
    <MenuItem Header="Add">
        <MenuItem Command="k:CustomCommands.AddCircle" />
    </MenuItem>
</Menu>
错误来自行“MenuItem Command=“k:CustomCommands.AddCircle””


非常感谢您的帮助!!

您的XML/CLR命名空间映射错误:您有
k
别名
GraphicsBook
,但是
CustomCommands
GraphicsBook.Assignment
中声明


您还可以尝试使用
{x:Static k:CustomCommands.AddCircle}
而不是简单地
k:CustomCommands.AddCircle

CustomCommands
Testbed2D
程序集中声明?是的,它是Testbed2D中的一个.cs文件。您是否尝试使用
x:Static
?Hm仍然给我同样的错误不幸的是
命令=“{x:Static k:CustomCommands.AddCircle}”“
出了问题。窗口是在同一个部件中,还是在不同的部件中?如果是其他程序集,则包含该窗口的项目是否引用了该命令的程序集?是否确定程序集名称与项目名称(Testbed2D)匹配?如果重命名了一个,则需要重命名另一个。
namespace GraphicsBook
{
    public partial class CustomCommandSample : Window
    {
        public CustomCommandSample()
        {
            ...
        }

        private void AddCircleCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
    }

    public static class CustomCommands
    {
        public static readonly RoutedUICommand AddCircle = new RoutedUICommand
            (
                    "AddCircle",
                    "AddCircle",
                    typeof(CustomCommands),
                    new InputGestureCollection()
                            {
                                    new KeyGesture(Key.F4, ModifierKeys.Alt)
                            }
            );
    }
}