The Xmal goes like this:
<Window x:Class="TouchBug.MainWindow"
xmlns=
xmlns:x=
Title="MainWindow" Height="220" Width="309">
<Grid>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="84,36,0,0" Name="textBlock1"
Text="2013-01-23 00:00:00" VerticalAlignment="Top" Width="172" />
<Canvas Height="53" HorizontalAlignment="Left" Margin="29,92,0,0" Name="canvas1"
VerticalAlignment="Top" Width="93" Background="Red" MouseDown="canvas1_MouseDown" />
<Canvas Height="53" HorizontalAlignment="Left" Margin="163,92,0,0" Name="canvas2"
VerticalAlignment="Top" Width="93" Background="Blue" MouseDown="canvas2_MouseDown" />
<Label Content="Time:" Height="28" HorizontalAlignment="Left" Margin="29,31,0,0" Name="label1"
VerticalAlignment="Top" Width="49" />
</Grid>
</Window>
And the codes behind are:
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void canvas1_MouseDown(object sender, MouseButtonEventArgs e)
{
textBlock1.Text = DateTime.Now.ToString();
}
private void canvas2_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("I'm a message box!", "Message", MessageBoxButton.OK);
e.Handled = true;
}
}
According to the codes, while we click the red canvas, the text after "Time:" will change to the current time, while we click the blue canvas, a MessageBox will be shown. As we expected, any time we click the two canvases with the mouse, the corresponding
MouseDown event is fired.
However, something is wrong while I run this application on a touch screen. firstly, I touch the blue canvas and get a MessageBox, then I touch the "OK" button to close the MessageBox. Secondly, I touch the red canvas, the MessageBox appears again. Not only the red canvas, touching any place on the Window the MessageBox comes out.
I don't know whether this bug is relatived with the touch device or not. Any advice is appreciated. Thanks in advance.
By the way, a similar WinForm application runs well on touch device.