Fem*_*jin 8 android listview xamarin.forms
我使用xamarin.forms创建了listview,我正在寻找一种在点击列表视图时不突出显示视单元的方法.
请查看下图.

提前致谢 :)
在ListView SelectedItem事件处理程序中,您可以执行以下操作:
listview.SelectedItem = null;
Run Code Online (Sandbox Code Playgroud)
这将给你点击突出显示,但状态只是暂时的.
在你的情况下,我猜你喜欢这个,因为你使用2 Image秒代替Buttons代表右边的箭头,用a TapGestureRecognizer.你知道Button有Image房产吗?单击a Button中的a时Cell,Cell所选状态不应更改.
只需将其放在您的自定义主题中:
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)
我想分享另一个我非常喜欢的解决方案,因为它很简单,您只需实现一次,并且在 XAML 中非常容易使用。
首先,我们必须实现我们自己的行为。这很简单:
public class DeselectItemBehavior : Behavior<ListView>
{
protected override void OnAttachedTo(ListView bindable)
{
base.OnAttachedTo(bindable);
bindable.ItemSelected += ListView_ItemSelected;
}
protected override void OnDetachingFrom(ListView bindable)
{
base.OnDetachingFrom(bindable);
bindable.ItemSelected -= ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
((ListView)sender).SelectedItem = null;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我们只是在设置行为时注册事件,并在未设置时取消注册。
事件本身使用 Stephane Delcroix 方法。
现在你在 ListView 中要做的就是添加这样的行为:
<ListView ...>
<ListView.Behaviors>
<behaviors:DeselectItemBehavior />
</ListView.Behaviors>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12174 次 |
| 最近记录: |