【发布时间】:2014-11-12 15:04:37
【问题描述】:
我在尝试在 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>
我的 CustomsCommand.cs 文件位于项目文件夹中。在这个文件中是:
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)
}
);
}
}
错误来自'MenuItem Command="k:CustomCommands.AddCircle"'行。
任何帮助将不胜感激!
【问题讨论】:
标签: c# wpf namespaces undefined