当我通过“Appkey”打开时,我遇到了上下文菜单的问题,请参考this link for same issue以供参考。在这里我没有通过 keyUp或Keydown 来处理事件,但是通过XAML Commandbinding和Inputbinding我在代码隐藏中打开上下文菜单,我的问题是如何让关键字菜单保持打开状态被释放。
<UserControl.CommandBindings>
<!--Custom Commands-->
<CommandBinding Command="my:ThumbnailImages.CustomCommandContextMenu" Executed="OpenContextMenu_Executed" />
</UserControl.CommandBindings>
<UserControl.InputBindings>
<KeyBinding Command="my:ThumbnailImages.CustomCommandContextMenu" Key="Apps"/>
</UserControl.InputBindings>
<ListBox.ContextMenu>
<ContextMenu Name="ZoneIformationList" StaysOpen="true" Background="WhiteSmoke">
<ContextMenu.BitmapEffect>
<BitmapEffectGroup/>
</ContextMenu.BitmapEffect>
<MenuItem Header="Edit" Name="EditNutritionContextMenu" />
<MenuItem Header="Remove" Name="RemoveNutritionContextMenu" />
</ContextMenu>
</ListBox.ContextMenu>
Private Sub OpenContextMenu_Executed(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
If IsNothing(MyList.ContextMenu) = False Then
MyList.ContextMenu.PlacementTarget = MyList
MyList.ContextMenu.IsEnabled = True
MyList.ContextMenu.IsOpen = True
e.Handled = True
End If
End Sub
End Class