且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xamarin.Forms untappable的ListView(删除选择连锁反应)

更新时间:2022-12-11 15:24:41

所以经过很长一段时间我们想通了,你可以用自定义渲染完成它。这里是怎么了,

So after a long, long time we figured it out, you can accomplish it with a custom renderer. Here is how,

首先,创建一个名为 no_selector.xml 文件并将其放置在资源/文件夹布局(包装性能必须。设为AndroidResource)

First, create a file called no_selector.xml and place it in the Resources/layouts folder (the packaging properties must be set to AndroidResource).

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:drawable="@android:color/transparent"/>
</selector>



之后,创建为ListView组件定制呈现,

After that create a custom renderer for the ListView component,

[assembly: ExportRenderer (typeof(ListView), typeof(NoRippleListViewRenderer))]
namespace Your.Own.Namespace
{
    public class NoRippleListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged (ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged (e);
            Control.SetSelector (Resource.Layout.no_selector);
        }
    }
}

如果 no_selector 文件无法找到重建项目!

If the no_selector file can't be found rebuild your project!

要注意的是,这将删除纹波为全部的在应用程序列表视图。如果你只希望它的目标一对夫妇,你可以更改ExportRenderer属性第一类(这确实需要你做一个扩展的ListView一个单独的类)。

Be aware of the fact that this removes the ripple for all the ListViews in your application. If you only want it to target a couple you can change the first type on the ExportRenderer attribute (this does require you to make a separate class that extends ListView).

一个样品可以在这里找到

A sample can be found here.