Xaml 点击事件,选择顶部有文本和图像的矩形
我正在尝试创建一个UI,它给最终用户一种平铺般的感觉。我有三个元素——矩形、文本和图像,如下所示:Xaml 点击事件,选择顶部有文本和图像的矩形,xaml,windows-phone-7.1,windows-phone-7,Xaml,Windows Phone 7.1,Windows Phone 7,我正在尝试创建一个UI,它给最终用户一种平铺般的感觉。我有三个元素——矩形、文本和图像,如下所示: <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"
<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事件处理程序。问题是,如果我只将它指定给矩形,那么如果用户单击文本或图像,它将不起作用。我想做一些事情,使文本和图像显示在矩形的顶部,加上整个矩形是可点击的,即它响应点击事件
正在寻找一种解决方案,该解决方案不涉及将相同的点击事件分配给文本块和图像将所有这些内容放入按钮并使用按钮事件:
<Button>
<Grid>
<Rectangle ... />
<TextBlock ... />
<Image ... />
</Grid>
</Button>
将所有这些内容放入按钮并使用按钮事件:
<Button>
<Grid>
<Rectangle ... />
<TextBlock ... />
<Image ... />
</Grid>
</Button>
将所有这些元素放入
网格中
或堆栈面板
,并使用该容器上的事件。它们可以包含多个控件作为子控件,并在矩形/textblock/image未捕获该事件时接受该事件。将所有这些元素放置到网格或堆栈面板中,并在该容器上使用该事件。它们可以包含多个控件作为子控件,并且在矩形/textblock/image未捕获该事件时将接受该事件。也许这有助于
XAML:
<Grid Tap="Grid_Tap">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Grid.Row="0"
Width="100" Height="100"
Fill="Red" />
<TextBlock Grid.Column="0" Grid.Row="0"
VerticalAlignment="Bottom" TextAlignment="Left"
Text="YourText" />
<Image Grid.Column="0" Grid.Row="0"
ImageSource="Images/YourImage.png" />
</Grid>
private void Grid_Tap(object sender, GestureEventArgs e)
{
MessageBox.Show("Hello World!");
}
也许这有助于
XAML:
<Grid Tap="Grid_Tap">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Grid.Row="0"
Width="100" Height="100"
Fill="Red" />
<TextBlock Grid.Column="0" Grid.Row="0"
VerticalAlignment="Bottom" TextAlignment="Left"
Text="YourText" />
<Image Grid.Column="0" Grid.Row="0"
ImageSource="Images/YourImage.png" />
</Grid>
private void Grid_Tap(object sender, GestureEventArgs e)
{
MessageBox.Show("Hello World!");
}
你不能那样做!我得到一个错误“属性内容设置了多次”对不起,也许它应该更复杂你不能这样做!我得到一个错误“属性内容设置了多次”对不起,也许它应该更复杂