[英]WPF - Name doesn't exist in namespace
I am having a namespace issue while trying to implement some custom bindings in WPF. 我在尝试在WPF中实现一些自定义绑定时遇到名称空间问题。 I am getting the error 'The name 'CustomCommands' does not exist in the namespace 'clr-namespace:GraphicsBook;assembly=Testbed2D".
我收到错误消息“名称'CustomCommands'在名称空间'clr-namespace:GraphicsBook; assembly = Testbed2D中不存在”。
In my XAML I have: 在我的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>
And my CustomsCommand.cs file is within the project folder. 我的CustomsCommand.cs文件位于项目文件夹中。 Within this file is:
该文件中包含:
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)
}
);
}
}
The error comes from the line 'MenuItem Command="k:CustomCommands.AddCircle"'. 错误来自“ MenuItem Command =“ k:CustomCommands.AddCircle””行。
Any help would be much appreciated!! 任何帮助将非常感激!!
Your XML/CLR namespace mapping is wrong: you have k
aliasing GraphicsBook
, but CustomCommands
is declared in GraphicsBook.Assignment
. 您的XML / CLR名称空间映射是错误的:您有
k
个别名GraphicsBook
,但CustomCommands
在GraphicsBook.Assignment
声明。
You can also try using {x:Static k:CustomCommands.AddCircle}
instead of simply k:CustomCommands.AddCircle
. 您也可以尝试使用
{x:Static k:CustomCommands.AddCircle}
而不是简单地使用k:CustomCommands.AddCircle
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.