從父級拖動到子級控件時,我得到了DragLeave事件。我只希望在控制範圍外移動時得到這個事件。我怎樣才能實現這個?WPF拖放 - DragLeave何時熄滅?
請參考這個簡單的示例應用程序。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBox Height="50" >Hilight and Drag this text</TextBox>
<Border BorderBrush="Blue" BorderThickness="2">
<StackPanel AllowDrop="True" Name="Stack" >
<Label >If I drag text across the gray line, Stack.DragLeave will fire.</Label>
<Separator></Separator>
<Label>I only expect to get this event when leaving the blue rectangle. </Label>
</StackPanel>
</Border>
<TextBlock >Stack.DragLeave Count: <Label x:Name="countLabel" /></TextBlock>
</StackPanel>
</Window>
,並在後面
Class MainWindow
Private Sub Stack_DragLeave(ByVal sender As Object, ByVal e As System.Windows.DragEventArgs) Handles Stack.PreviewDragLeave
countLabel.Content = countLabel.Content + 1
End Sub
End Class
[的DragDrop - dragEnter事件/ DragLeave事件持續開火]的可能重複(http://stackoverflow.com/questions/2632821/dragdrop-dragenter-dragleave-events-keep - 發射) – 2015-08-11 19:29:55