I made the following application (as a test)
XAML:
<Window x:Class="GUITest.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"> <Grid Background="Transparent"> <TextBlock Text="openDialog" Background="Red" HorizontalAlignment="Center" VerticalAlignment="Top" MouseDown="TextBlock_MouseDown" /> </Grid> </Window>
WITH#:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); Nullable<bool> result = dlg.ShowDialog(); if (result == true) { Console.Out.WriteLine(dlg.FileName); } } }
I will catch the mouseDown event because it catches mouse events and mouse buttons. The code has the expected behavior for mouse clicks. Touching causes some problems.
If I touch TextBlock, it will open a dialog box as specified. after closing it, any touch of the window opens a dialog box, even if the touch was not in the TextBlock.
This is mistake? Can I get around this?
EDIT: I posted a workaround, the actual fix will still be useful
source share