我有ListView
<ListView x:Name="lstBWDetails" Grid.Row="2" Width="{Binding ActualWidth,ElementName=MainGrid}"
ItemTemplate="{StaticResource ItemFavoriteWord}"
ItemClick="lstBWDetails_ItemClick" IsItemClickEnabled="True"
Tapped="lstBWDetails_Tapped" >
</ListView>
和DataTemplate
<DataTemplate x:Key="ItemFavoriteWord">
<Grid Width="400" Margin="10 0 5 2" Height="50" Background="#f0f0f1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<StackPanel Margin="0 0 0 0" Orientation="Vertical" HorizontalAlignment="Left" Grid.Column="0" Tapped="StackPanel_Tapped">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding en}" Tag="{Binding en}" TextWrapping="Wrap" FontSize="18" Foreground="#c8454d" Margin="15 0 0 0" />
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding local}" Tag="{Binding en}" TextWrapping="Wrap" FontSize="18" Foreground="#0577bb" Margin="15 0 0 0" />
</StackPanel>
<StackPanel Margin="0 0 10 0" Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1" >
<Image Height="40" Name="imgFav" Width="50" Margin="0 0 10 0" Tapped="imgFav_Tapped" Source="{Binding favo}" Tag="{Binding id}" />
</StackPanel>
<Border Grid.ColumnSpan="2" Grid.Column="0" BorderBrush="#FFC9C9C9" BorderThickness="0,0,0,0.5" >
</Border>
</Grid>
</DataTemplate>
当我点击ListView项目点击 - &gt;好 但是当我点击imgFav_tapped时 - > ListView项目点击首先激活,第二个imgFav_Tapped激活第二个
所以我想在我点击imgFav_Tapped
时禁用ListView项目抱歉,我的英文不好
答案 0 :(得分:0)
您可以尝试在模板中的单个控件内处理click事件,但这可能不是您想要的...
我通常解决这个问题的方法是禁用itemclick,而是处理Tapped事件,通过OriginalSource将任何对象转换为FrameworkElement,这样我就可以提取datacontext并尝试对实际点击的项目作出适当的反应。
类似这样的事情
private void List_Tapped(object sender, TappedRoutedEventArgs e)
{
var source = e.OriginalSource as FrameworkElement;
if (source == null) return;
var item = source.DataContext as MyItemClass;
if (item == null) return;
// do stuff with your item
}
不是一个完全直截了当的解决方案,但我希望这对您更接近您所寻找的内容有所帮助!