ListViewItem中有多个控件,在我将事件代理方法添加到Textblock后,它首先调用ListView.ItemClick
事件,然后调用TextBlock.Tapped
事件。
但,有一项功能,即当用户点击Textblock
,时,只需调用Textblock.Tapped
事件而不调用ListView.ItemClick
事件,当用户点击控件不是TextBlock时,调用ListView.ItemClick
事件
XAML:
<ListView ItemClick="ListView_ItemClick">
<ListViewItem>
<StackPanel>
<Image/>
<!-- other controls -->
<TextBlock Tapped="TextBlock_Tapped"/>
</StackPanel>
</ListViewItem>
</ListView>
答案 0 :(得分:2)
当指针进入ItemClick
时禁用TextBlock
事件,并在指针退出ItemClick
事件时重新启用它
在XAML中
<ListView Name="MyListView" ItemClick="MyListView_ItemClick">
<ListViewItem>
<StackPanel>
<Image/>
<!-- other controls -->
<TextBlock Tapped="TextBlock_Tapped"/>
</StackPanel>
</ListViewItem>
</ListView>
在Code背后
private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
{
}
private void MyListView_ItemClick(object sender, ItemClickEventArgs e)
{
}
private void TextBlock_PointerEntered(object sender, PointerRoutedEventArgs e)
{
MyListView.IsItemClickEnabled = false;
}
private void TextBlock_PointerExited(object sender, PointerRoutedEventArgs e)
{
MyListView.IsItemClickEnabled = true;
}