Reputation: 1014
I am having a namespace issue while trying to implement some custom bindings in WPF. I am getting the error 'The name 'CustomCommands' does not exist in the namespace 'clr-namespace:GraphicsBook;assembly=Testbed2D".
In my XAML I have:
<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. 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"'.
Any help would be much appreciated!!
Upvotes: 1
Views: 1480
Reputation: 25623
Your XML/CLR namespace mapping is wrong: you have k
aliasing GraphicsBook
, but CustomCommands
is declared in GraphicsBook.Assignment
.
You can also try using {x:Static k:CustomCommands.AddCircle}
instead of simply k:CustomCommands.AddCircle
.
Upvotes: 1