我想在C#中将自定义命令添加到我的项目中。要做到这一点,我已经添加了一个新的类,我的项目:XAML CommandBinding在本地命名空间中不存在?
using System.Windows.Input;
namespace DataBindingHuiswerk
{
public static class CustomCommands
{
public static readonly RoutedUICommand Add = new RoutedUICommand(
"Add",
"Add",
typeof(CustomCommands),
new InputGestureCollection()
{
new KeyGesture(Key.F1, ModifierKeys.Control)
}
);
public static readonly RoutedUICommand Change = new RoutedUICommand(
"Change",
"Change",
typeof(CustomCommands),
new InputGestureCollection()
{
new KeyGesture(Key.F2, ModifierKeys.Control)
}
);
public static readonly RoutedUICommand Delete = new RoutedUICommand(
"Delete",
"Delete",
typeof(CustomCommands),
new InputGestureCollection()
{
new KeyGesture(Key.F3, ModifierKeys.Control)
}
);
}
}
接下来我想在我的XAML代码绑定这些:
<Window x:Class="DataBindingHuiswerk.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DataBindingHuiswerk"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<CommandBinding Command="local:CustomCommands.Add" Executed="AddCommand_Executed" CanExecute="AddCommand_CanExecute" />
然而,这将返回我:
名称 “CustomCommands” 没有命名空间中存在 “CLR的命名空间:DataBindingHuiswerk”
现在我可能在这里错了,但是对我来说CustomCommands
明显存在于DataBindingHuiswerk
命名空间内吗?我错过了什么吗?
“回报我”是否意味着它不会建立? –
@EdPlunkett不,这意味着我的项目显示“Invalid Markup”,并且将鼠标悬停在错误下划线部分上:'Command =“local:CustomCommands.Add”'它会返回该消息。 – icecub
啊。它会建立吗? –