如果单击自己的UserControl则捕获

时间:2013-08-19 20:20:20

标签: c# xaml windows-phone-8 mouseevent

我正在为Windows Phone 8编写Wordsearch游戏。

screen http://kepfeltoltes.hu/130804/j_t_k_www.kepfeltoltes.hu_.png

这是游戏窗口,那些矩形是自己的UserControls。 以下是XAML中矩形的定义:

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Rectangle x:Name="Kitoltoszin" Stroke="White" Width="100" Height="100" StrokeThickness="3" RadiusX="10" RadiusY="10" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Rectangle.Fill>
                <SolidColorBrush Color="Gray"/>                
            </Rectangle.Fill>
        </Rectangle>
        <TextBlock x:Name="Betu" Width="70" Height="70" 
                   FontWeight="Bold" FontSize="42" Foreground="White" 
                   HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" />
    </Grid>

我想要做的是检测触摸了哪个矩形并用它做了一些事情(例如使其背景为蓝色)。有一个简单的方法吗?如何在WP8中刷新页面?

1 个答案:

答案 0 :(得分:1)

因此您需要使用Rectangle的{​​{3}}事件,因此您将添加标记:

MouseLeftButtonUp="Kitoltoszin_MouseLeftButtonUp"

然后在代码隐藏中添加处理程序:

private void Kitoltoszin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // do what you want here
}