【发布时间】:2016-09-26 01:15:03
【问题描述】:
我正在尝试将自定义命令添加到我的 C# 项目中。为此,我在我的项目中添加了一个新类:
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" />
但是,这会返回我:
命名空间“clr-namespace:DataBindingHuiswerk”中不存在名称“CustomCommands”
现在我可能在这里错了,但对我来说 CustomCommands 显然存在于 DataBindingHuiswerk 命名空间中?我错过了什么吗?
【问题讨论】:
-
“返回我”是否意味着它不会构建?
-
@EdPlunkett 不,这意味着我的项目显示“无效标记”,当将鼠标悬停在错误下划线部分时:
Command="local:CustomCommands.Add"它会返回该消息。 -
错误信息具有如此离奇的误导性这一事实表明该问题值得保留。
-
@KosalaW 好的,我不会。
-
@EdPlunkett 如果你真的做队友,整个世界都注定要失败,所以交给我们其他人吧 xD