问题
I got a problem with context menu when i open through "Appkey" please refer this link for same issue for reference. Here i did't handle the event through keyUp or Keydown, but through XAML Commandbinding and Inputbinding i'm opening the context menu in codebehind, my problem is how to make context menu remain open even when the key is released.
<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
来源:https://stackoverflow.com/questions/18332120/wpf-context-menu-disappears-when-key-app-is-released