gpt4 book ai didi

c# - ContextMenu 导致所有其他 UI 元素不可点击

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:03 25 4
gpt4 key购买 nike

我有几个具有以下样式的 ContextMenus:

    <Style TargetType="{x:Type ContextMenu}" x:Key="ListBoxContextMenu">
<Setter Property="BorderBrush" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border Margin="14" Background="White">
<Border.Effect>
<DropShadowEffect Opacity="0.999" BlurRadius="8" ShadowDepth="0"/>
</Border.Effect>
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

我有一个 ContextMenu 用于 ListBox,另一个用于按钮(Think Chrome 类型设置菜单)。如果我通过再次单击按钮或单击表单上的任何其他位置关闭按钮的上下文菜单,禁止列表框,它会正常关闭,我可以继续正常使用该程序。但是,如果我通过单击 ListBox 关闭 ContextMenu,我只能使用 ListBox,直到我单击“n”拖动 ListBoxItems 之一,之后我可以使用关闭、最小化、搜索等按钮。

供引用的窗口图像:

Please ignore the actual text :D

ListBoxItem 单击/拖动的代码

Private Sub ReferenceListItemMouseDown(sender As Object, e As MouseButtonEventArgs)
Dim PW As MainWindow = Window.GetWindow(MainPage)
StartPoint = e.GetPosition(Nothing)
PW.Resizing = False
End Sub

Private Sub ReferenceListItemMouseMove(sender As Object, e As MouseEventArgs)
Dim PW As MainWindow = Window.GetWindow(MainPage)
If PW.Resizing = False Then
Dim MousePosition As Point = e.GetPosition(Nothing)
Dim Difference As Vector = StartPoint - MousePosition
Dim StopDrop As Boolean
If e.LeftButton = MouseButtonState.Pressed AndAlso (Math.Abs(Difference.X) > SystemParameters.MinimumHorizontalDragDistance Or Math.Abs(Difference.Y) > SystemParameters.MinimumVerticalDragDistance) Then
Dim LB As ListBox = ReferenceList
Dim UIE As UIElement = LB.InputHitTest(MousePosition)
If UIE IsNot Nothing Then
Dim Data As Object = DependencyProperty.UnsetValue
While Data Is DependencyProperty.UnsetValue And UIE IsNot Nothing
Data = LB.ItemContainerGenerator.ItemFromContainer(UIE)
If Data Is DependencyProperty.UnsetValue Then
UIE = VisualTreeHelper.GetParent(UIE)
End If
If UIE Is LB Then
StopDrop = True
End If
End While
If Data IsNot DependencyProperty.UnsetValue Then
StopDrop = False
End If
Else
StopDrop = True
End If
PW.TempItem = LB.SelectedItem
Dim FN As String = PW.TempItem.PropLastName & ", " & PW.TempItem.PropFirstName.Substring(0, 1)
Dim TT As String = PW.TempItem.PropTitle
Dim YR As String = PW.TempItem.PropYear.ToString
Dim ReferenceText As String = FN & " " & YR & ", " & TT
Dim DragData As DataObject = New DataObject(DataFormats.StringFormat, ReferenceText)
If DragData IsNot Nothing And StopDrop = False Then
DragDrop.DoDragDrop(sender, DragData, DragDropEffects.Copy)
End If
End If
End If

End Sub

我有预感,是 MouseDown 和 MouseMove 事件导致了这个问题。如果有人能发现问题或需要更多信息,请告诉我。提前致谢。

最佳答案

没关系。我解决了这个问题。我所做的是摆脱 UIElement while 语句和相关代码。然后,我将其替换为简单的 TryCast(sender, ListBoxItem)。如果您需要更详细的解释,请告诉我,我会尽快回复您。

关于c# - ContextMenu 导致所有其他 UI 元素不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13943879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com