Xamarin.Forms untappable的ListView(删除选择连锁反应) [英] Xamarin.Forms untappable ListView (remove selection ripple effect)
问题描述
我有一个自定义的ViewCell显示文章一个ListView。然而,当你选择一个项目,它显示了材料设计涟漪/选择效应。
I have a ListView with a custom ViewCell that displays articles. However when you select a item, it shows the material design ripple/selection effect.
的XAML:
<ListView HasUnevenRows="True" ItemsSource="{Binding NewsArticles}" IsPullToRefreshEnabled="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding Title}" HorizontalOptions="Center" FontAttributes="Bold" />
<Image Source="{Binding ImageUrl}" IsVisible="{Binding HasImage}" />
<Label Text="{Binding Content}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我如何删除的连锁反应?
How do I remove the ripple effect?
更新:
在做一些研究,我发现的在XLabs库RepeaterView 。如果你把它包装在滚动型,虽然它带走了很多的ListView整齐力学的,如清爽的这个作品。它也不支持从外螺纹到的ItemSource变化。还在寻找其他的解决办法,因为我知道这是有可能在原生的Android。
After doing some research I found the RepeaterView in the XLabs library. This works if you wrap it in a ScrollView although it takes away a lot of the neat ListView mechanics such as refreshing. It also doesn't support changes to the ItemSource from an external thread. Still looking for other solutions since I know this is possible in native Android.
推荐答案
所以经过很长一段时间我们想通了,你可以用自定义渲染完成它。这里是怎么了,
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.
这篇关于Xamarin.Forms untappable的ListView(删除选择连锁反应)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!