禁用列表上的突出显示单击以查看xaml页面Xamarin.Forms

时间:2016-11-22 12:55:55

标签: xaml xamarin xamarin.forms

我在xaml页面中有List:

<ListView x:Name="ListTypeView" ItemsSource="{Binding ResourceType}" BackgroundColor="#FFFFFF" HeightRequest="210" WidthRequest="300" HorizontalOptions="CenterAndExpand" RowHeight="30">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout StyleId="Settings_StackLayout" Orientation="Horizontal" Padding="0" Margin="50,0,0,0">
                    <Label FontSize="Medium" HorizontalOptions="StartAndExpand" Text="{Binding ResourceType}" TextColor="Black" VerticalOptions="Center" WidthRequest="100"></Label>
                    <Image x:Name="Image" Source="{Binding Checkbox}" HorizontalOptions="StartAndExpand" WidthRequest="18" HeightRequest="18">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding Source={x:Reference ListTypeView}, Path=BindingContext.ListTypeChangeCommand}" CommandParameter="{Binding .}"/>
                        </Image.GestureRecognizers>
                    </Image>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我想禁用listView上的高亮显示 (删除列表默认为蓝色的选择器)

1 个答案:

答案 0 :(得分:0)

如果您在图像上定义TapGestureRecognizer,那么如果您点击图像,则无论如何都不应选择列表项。如果要在项目点击上禁用选择器,则需要使用不同的事件 - 列表项目轻触

    lstItems.ItemTapped += LstItems_ItemTapped;

然后

 private void LstItems_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            //do whatever you need with selected item and reset it
            ((ListView)sender).SelectedItem = null;
        }