C# ContextMenu导致所有其他UI元素不可访问
我有两个具有以下样式的上下文菜单:C# ContextMenu导致所有其他UI元素不可访问,c#,wpf,vb.net,user-interface,contextmenu,C#,Wpf,Vb.net,User Interface,Contextmenu,我有两个具有以下样式的上下文菜单: <Style TargetType="{x:Type ContextMenu}" x:Key="ListBoxContextMenu"> <Setter Property="BorderBrush" Value="White"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Ba
<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>
我有一种预感,是MouseDown和MouseMove事件导致了这个问题。如果有人能发现问题或需要更多信息,请告诉我。提前谢谢。没关系。我解决了这个问题。我所做的是,去掉UIElement while语句和相关代码。然后我用一个简单的TryCast(sender,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