我创建了一个带有文本块和图像的 LongListSelector,然后单击标题以显示选定的员工姓名,然后单击图像以显示另一个消息框。如果我单击名称,则消息框显示成功。当我点击图片时,图片的消息框显示成功,但也显示了员工姓名的消息框。我该如何解决这个问题?
我使用下面的代码:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="TileDataTemplate">
<Grid Background="{StaticResource TransparentBrush}"
Margin="0, 0, 0, 12" Height="60">
<TextBlock Text="{Binding Name}" Margin="60, 10, 0, 0" FontSize="24" Height="60">
</TextBlock>
<Image x:Name="delete" Tap="delete_Tap" Grid.Column="0" Source="/Assets/AppBar/Delete.png" Height="40" Width="40"
Margin="0, 6, 0, 5" HorizontalAlignment="Right" VerticalAlignment="Top" />
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector
SelectionChanged="MainLongListSelector_SelectionChanged"
Margin="10,6,0,0"
ItemsSource="{Binding Staff.Items}"
LayoutMode="Grid"
GridCellSize="400,80"
ItemTemplate="{StaticResource TileDataTemplate}"
/>
</Grid>
结果如下打印屏幕:
代码背后:
private void MainLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector selector = sender as LongListSelector;
StaffData data = selector.SelectedItem as StaffData;
MessageBox.Show(data.Name);
}
private void delete_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBox.Show("delete?");
}
请教我如何解决这个问题。谢谢。