【发布时间】:2017-02-07 15:45:54
【问题描述】:
我正在尝试实现命令绑定,以便我的用户可以使用 Alt+ 进行导航。我找到了this 示例,但在形成 xmlns 和 CommandBinding xaml 时遇到问题。
这是我目前所拥有的。我知道它的格式不正确。
xmlns:local="clr-namespace:xxxxx"
<Window.CommandBindings>
<CommandBinding
Command="{x:Static local:xxxxx.ProjectMsg}"
Executed="ProjectMsg"/>
</Window.CommandBindings>
该命令的编码在 MainWindow vb 中:
Class MainWindow
Public Shared ProjectTab_AltP As New RoutedCommand
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
ProjectTab_AltP.InputGestures.Add(New KeyGesture(Key.P, ModifierKeys.Control))
Me.CommandBindings.Add(New CommandBinding(ProjectTab_AltP, AddressOf Me.ProjectMsg))
End Sub
Private Sub ProjectMsg(sender As Object, e As ExecutedRoutedEventArgs)
MessageBox.Show("hi")
End Sub
我收到一个错误,名称空间 clr-namespace:xxxxx 中不存在名称“xxxxx”。
在主窗口 vb 中,没有声明命名空间。如果我尝试添加一个,则会出现许多错误。
我必须在主窗口 vb 中有一个命名空间吗?
我是 wpf 的菜鸟,因此我将不胜感激任何帮助或建议。谢谢。
【问题讨论】: