您的当前位置:首页正文

Xamarin.Forms 中ListView 修改选中效果

来源:华佗健康网

在Xamarin.Forms中ListView是非常常用的控件之一,ListView有一个默认的选中效果,颜色和自己的App很不搭,怎么办呢?

1. 在很多时候,ListView在使用中不需要选中,更多情况下,只是点击一下而已,那么我们可以将其SelectMode设置为None。

<ListView 
    BackgroundColor="Transparent"
    temsSource="{Binding PasswordList}" 
    RowHeight="96" Margin="12"  SelectionMode="None"
    ItemTapped="ListView_ItemTapped" SeparatorVisibility="None"
    SeparatorColor="Transparent"/>    

2. 如果需要修改选中效果颜色怎么处理呢?

首先,自定义ExtendedViewCell继承ViewCell;

  

public class ExtendedViewCell : ViewCell
  {
    public static readonly BindableProperty SelectedBackgroundColorProperty =
        BindableProperty.Create("SelectedBackgroundColor", 
                                typeof(Color), 
                                typeof(ExtendedViewCell), 
                                Color.Default);

    public Color SelectedBackgroundColor
    {
      get { return (Color)GetValue(SelectedBackgroundColorProperty); }
      set { SetValue(SelectedBackgroundColorProperty, value); }
    }
  }

然后,根据各个平台为ExtendedViewCell提供一个Renderer(ExtendedViewCellRenderer)

Android:

iOS:

这样就能修改选中效果啦。

 

 

转载于:https://www.cnblogs.com/devin_zhou/p/9398980.html

因篇幅问题不能全部显示,请点此查看更多更全内容