WPF Context menu disappears when Key.App is released

人走茶凉 提交于 2019-12-25 11:57:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!