WPF 键手势 PageDown 在菜单项中显示为“Next”
我已经设置了一个使用 PageDown 作为关键手势的自定义命令,但对于绑定到该命令的 MenuItem,手势显示为“下一步”。问题是我有一些命令使用 PageUp、Home 和 End 来执行相关任务,并且它们都按预期的菜单项显示。有没有办法让 MenuItem 显示“PageDown”而不是“Next”以保持一致性?
这是定义命令的 xaml。
<Window.Resources>
<RoutedUICommand x:Key="FirstPageCommand"
Text="FirstPage">
<RoutedUICommand.InputGestures>
<KeyGesture>Home</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="LastPageCommand"
Text="LastPage">
<RoutedUICommand.InputGestures>
<KeyGesture>End</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="PreviousPageCommand"
Text="PreviousPage">
<RoutedUICommand.InputGestures>
<KeyGesture>PageUp</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="NextPageCommand"
Text="NextPage">
<RoutedUICommand.InputGestures>
<KeyGesture>PageDown</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
</Window.Resources>
这是我在菜单中使用它们的地方
<MenuItem Header="_View">
<MenuItem Header="_First Page"
Command="{StaticResource FirstPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Backward_01.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Previous Page"
Command="{StaticResource PreviousPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Backward.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Next Page"
Command="{StaticResource NextPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Forward.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Last Page"
Command="{StaticResource LastPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Forward_01.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
我的菜单看起来像这样
- View
- First Page Home
- Last PageUp
- Next Page Next
- Last Page End
I've setup a custom command with PageDown as the key gesture, but for the MenuItem that is bound to that command the gesture shows up as "Next". The problem is that I have commands that use PageUp, Home, and End for related tasks and they all show up as expected for their MenuItems. Is there some way to make the MenuItem show "PageDown" instead of "Next" for consistency?
Here's the xaml that defines the commands.
<Window.Resources>
<RoutedUICommand x:Key="FirstPageCommand"
Text="FirstPage">
<RoutedUICommand.InputGestures>
<KeyGesture>Home</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="LastPageCommand"
Text="LastPage">
<RoutedUICommand.InputGestures>
<KeyGesture>End</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="PreviousPageCommand"
Text="PreviousPage">
<RoutedUICommand.InputGestures>
<KeyGesture>PageUp</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="NextPageCommand"
Text="NextPage">
<RoutedUICommand.InputGestures>
<KeyGesture>PageDown</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
</Window.Resources>
And here is where I use them in a Menu
<MenuItem Header="_View">
<MenuItem Header="_First Page"
Command="{StaticResource FirstPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Backward_01.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Previous Page"
Command="{StaticResource PreviousPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Backward.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Next Page"
Command="{StaticResource NextPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Forward.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Last Page"
Command="{StaticResource LastPageCommand}">
<MenuItem.Icon>
<Image Source="Images\Forward_01.png"
Stretch="Uniform"/>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
My menu looks like this
- View
- First Page Home
- Last Page PageUp
- Next Page Next
- Last Page End
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,只有当您在这样的代码中定义命令时,这才有可能。
以下是如何连接它们。
为什么
KeyGesture
不允许您在 xaml 中设置显示名称,这超出了我的理解范围。Apparently this is only possible if you define your commands in code like this.
And here's how you'd wire them up
Why the
KeyGesture
doesn't allow you to set the display name in xaml is beyond me.