顶部带有文本和图像的矩形的点击事件 [英] Tap event for a rectangle with text and image on top of it

查看:22
本文介绍了顶部带有文本和图像的矩形的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用户界面,为最终用户提供一种类似磁贴的感觉.我有以下三个元素 - 矩形、文本和图像:

I am trying to create a UI which gives a tile like feel to the end user. I have three elements - rectangle,text and image in the following manner:

<Rectangle Name="systemTime" Height="173" Width="173" Grid.Column="0" Grid.Row="0" Fill="{StaticResource PhoneAccentBrush}" Opacity="0.85" Margin="0,12,12,12" />
<TextBlock Text="System Time" Grid.Row="0" Grid.Column="0" FontSize="{StaticResource PhoneFontSizeMediumLarge}" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="12,0,0,15" />
<Image Source="images\System time.jpg" Grid.Row="0" Grid.Column="0" Width="150" Height="115" HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.9" Margin="-10,0,0,20" />

现在我想为矩形分配一个 Tap 事件处理程序.问题是,如果我只将它分配给矩形,那么如果用户单击文本或图像,它就不起作用.我想做一些事情,使文本和图像出现在矩形顶部,并且整个矩形都是可点击的,即它响应点击事件!

Now I want to assign a Tap event handler to the rectangle. The problem is that if I assign it only to the rectangle then it doesn't work if the user clicks on the text or image. I want to do something such that the the text and image appear on top of the rectangle plus the entire rectangle is clickable, i.e. it responds to the tap event!

寻找不涉及将相同的点击事件分配给 Textblock 和 Image 的解决方案

Looking for a solution which does not involve assigning the same tap event to the Textblock and Image

推荐答案

将所有这些元素放入 GridStackPanel 并在该容器上使用事件.它们可以包含多个作为子控件的控件,并且当它没有被矩形/文本块/图像捕获时将采用该事件.

Place all these elements into a Grid or StackPanel and use the event on that container. They can contain more then one control as the children and will take that event when it's not caught by rectangle/textblock/image.

这篇关于顶部带有文本和图像的矩形的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆