我想在WPF中为我的Menu做一些捷径。我用RoutedCommands创建了一个静态类,但是我无法让它工作。它说我的标记是无效的,但是我写得很好。我得到的错误是:“None+D6”键和修饰符组合不支持KeyGesture。我的RoutedCommands中任何地方都没有使用过RoutedCommands。
相关XAML
Window x:Class="WorldResources.GlowingEarth"
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:cmd="clr-namespace:WorldResources.View"/>
<Window.CommandBindings>
<CommandBinding Command="cmd:RoutedCommands.NewMap" Executed="NewFile_Click" />
</Window.CommandBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"></DockPanel>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="File">
<MenuItem Header="New">
<MenuItem Header="_Map" Command="cmd:RoutedCommands.NewMap" />
</MenuItem>
</Menu>
</DockPanel>这是我的RoutedCommands课程
static class RoutedCommands
{
public static RoutedUICommand NewMap = new RoutedUICommand(
"New Map",
"NewMap",
typeof(RoutedCommands),
new InputGestureCollection()
{
new KeyGesture(Key.M & Key.A, ModifierKeys.Control & ModifierKeys.Shift)
}
);
}有什么问题吗?
发布于 2017-05-30 13:18:52
您的KeyGesture无效。如果您想要处理CTRL+Shift +M和CTRL+Shift +A,请尝试这样做:
static class RoutedCommands
{
public static RoutedUICommand NewMap = new RoutedUICommand(
"New Map",
"NewMap",
typeof(RoutedCommands),
new InputGestureCollection()
{
new KeyGesture(Key.M, ModifierKeys.Control | ModifierKeys.Shift),
new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift)
}
);
}https://stackoverflow.com/questions/44263099
复制相似问题