title: ShowDialog Allowing Event Triggers on MainWindow Underneath WPF VB.NET
body: <p>I have a main window and a dialog window.  The mainwindow has a path on it with a PreviewMouseLeftButtonUp event and a button.  The button opens a 'ShowDialog' for my dialog window.  This dialog window has a label on it with a PreviewMouseLeftButtonDown event that closes the dialog.  The dialog opens directly over the path.  When I click the label to close the dialog, the path PreviewMouseLeftButtonUp event also fires.  How do I prevent this?  I hope this makes sense and thanks for any help you can give me on this.</p>
  <p>Here is my code for the MainWindow:</p>
  <pre><code>&lt;Window x:Class=&quot;MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:local=&quot;clr-namespace:DialogTest&quot;
      mc:Ignorable=&quot;d&quot;
      Title=&quot;MainWindow&quot; Height=&quot;695&quot; Width=&quot;958&quot; WindowStartupLocation=&quot;CenterScreen&quot;&gt;
  &lt;Grid&gt;
      &lt;Button x:Name=&quot;button&quot; Content=&quot;Button&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;62&quot; Margin=&quot;10,0,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;138&quot; /&gt;
  
      &lt;Path Data=&quot;M0,0L32,0 32,32 0,32z&quot; Stretch=&quot;Uniform&quot; Fill=&quot;Red&quot; Margin=&quot;-167,62,-76,0&quot; RenderTransformOrigin=&quot;0.5,0.5&quot;  PreviewMouseLeftButtonUp=&quot;Path_PreviewMouseLeftButtonUp&quot;&gt;
          &lt;Path.RenderTransform&gt;
              &lt;TransformGroup&gt;
                  &lt;TransformGroup.Children&gt;
                      &lt;RotateTransform Angle=&quot;0&quot; /&gt;
                      &lt;ScaleTransform ScaleX=&quot;1&quot; ScaleY=&quot;1&quot; /&gt;
                  &lt;/TransformGroup.Children&gt;
              &lt;/TransformGroup&gt;
          &lt;/Path.RenderTransform&gt;
      &lt;/Path&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p>The code behind for the MainWindow:</p>
  <pre><code>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(&quot;ClickedPreview&quot;)
  End Sub
  </code></pre>
  <p>End Class</p>
  <p>The code for the dialog window:</p>
  <pre><code>&lt;Window x:Class=&quot;dialog&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:local=&quot;clr-namespace:DialogTest&quot;
      mc:Ignorable=&quot;d&quot;
      Title=&quot;dialog&quot; Height=&quot;146&quot; Width=&quot;132&quot; WindowStartupLocation=&quot;CenterScreen&quot;&gt;
  &lt;Grid&gt;
      &lt;Label x:Name=&quot;label&quot; Content=&quot;Label&quot; HorizontalAlignment=&quot;Center&quot; Height=&quot;88&quot; Margin=&quot;0,10,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;112&quot;/&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p>And the code behind for the dialog window:</p>
  <pre><code>Public Class dialog
  Private Sub label_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles label.PreviewMouseLeftButtonDown
      Me.Close()
  End Sub
  </code></pre>
  <p>End Class</p>