我有一個主視窗和一個對話視窗。主視窗上有一個帶有 PreviewMouseLeftButtonUp 事件和一個按鈕的路徑。該按鈕為我的對話視窗打開一個“ShowDialog”。此對話框視窗上有一個標簽,帶有用于關閉對話框的 PreviewMouseLeftButtonDown 事件。對話框直接在路徑上打開。當我單擊標簽關閉對話框時,路徑 PreviewMouseLeftButtonUp 事件也會觸發。我如何防止這種情況?我希望這是有道理的,并感謝您在這方面給我的任何幫助。
這是我的 MainWindow 代碼:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DialogTest"
mc:Ignorable="d"
Title="MainWindow" Height="695" Width="958" WindowStartupLocation="CenterScreen">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="62" Margin="10,0,0,0" VerticalAlignment="Top" Width="138" />
<Path Data="M0,0L32,0 32,32 0,32z" Stretch="Uniform" Fill="Red" Margin="-167,62,-76,0" RenderTransformOrigin="0.5,0.5" PreviewMouseLeftButtonUp="Path_PreviewMouseLeftButtonUp">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
MainWindow 背后的代碼:
Class MainWindow
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
Dim win As New dialog
win.ShowDialog()
End Sub
Private Sub Path_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
End Sub
Private Sub Path_PreviewMouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
MsgBox("ClickedPreview")
End Sub
結束班
對話框視窗的代碼:
<Window x:Class="dialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DialogTest"
mc:Ignorable="d"
Title="dialog" Height="146" Width="132" WindowStartupLocation="CenterScreen">
<Grid>
<Label x:Name="label" Content="Label" HorizontalAlignment="Center" Height="88" Margin="0,10,0,0" VerticalAlignment="Top" Width="112"/>
</Grid>
以及對話框視窗背后的代碼:
Public Class dialog
Private Sub label_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles label.PreviewMouseLeftButtonDown
Me.Close()
End Sub
結束班
uj5u.com熱心網友回復:
只是讓任何人知道我通過將標簽更改為按鈕來解決此問題。按鈕單擊事件不會觸發下方的單擊事件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378931.html
上一篇:DatagridviewDataTable一次編輯、更新和顯示VB.net
下一篇:在類函式中獲取API
