释放Key.App时,WPF上下文菜单消失

释放Key.App时,WPF上下文菜单消失,wpf,listbox,keyboard,contextmenu,shortcut,Wpf,Listbox,Keyboard,Contextmenu,Shortcut,当我通过“Appkey”打开上下文菜单时遇到问题,请参考。在这里,我没有通过键向上或键向下处理事件,但通过XAML Commandbinding和Inputbinding,我在codebehind中打开上下文菜单,我的问题是如何使上下文菜单即使在释放键时也保持打开状态 <UserControl.CommandBindings> <!--Custom Commands--> <CommandBinding Command="my:

当我通过“Appkey”打开上下文菜单时遇到问题,请参考。在这里,我没有通过键向上或键向下处理事件,但通过XAML Commandbinding和Inputbinding,我在codebehind中打开上下文菜单,我的问题是如何使上下文菜单即使在释放键时也保持打开状态

  <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

私有子OpenContextMenu_已执行(ByVal sender作为System.Object,ByVal e作为System.Windows.Input.ExecutedRoutedEventArgs)
如果IsNothing(MyList.ContextMenu)=False,则
MyList.ContextMenu.PlacementTarget=MyList
MyList.ContextMenu.IsEnabled=True
MyList.ContextMenu.IsOpen=True
e、 已处理=真
如果结束
端接头
末级
如果您提供了所有必要的代码,那么我们可以将其放入新的WPF应用程序中,并为您进行测试和/或调试。我无法运行这段代码,因为您遗漏了大部分代码。尽量简化您的代码示例,使其只包含最小值。。。删除不相关的部分通常有助于我们找到解决方案。@Sheridan的问题在于“ExecuteMethod”,当我给快捷键时,此方法在“KeyDown”处处理事件,而“Appkey”事件在“KeyUp”处发生,我如何覆盖“ExecuteMethod”的defalut功能,还需要更多代码。谢谢你的答复。