【问题标题】:Disable selecting Items in ListView禁用在 ListView 中选择项目
【发布时间】:2018-07-21 13:48:46
【问题描述】:

对于我正在开发的社交网络应用程序,我正在尝试使用 ListView 显示 cmets,但我不希望在单击时突出显示它。

我尝试过使用

`((ListView)sender).SelectedItem = null;` in a selected event but that still shows it being selected for a second. I need it to never show.

我也尝试将列表视图设置为

IsEnabled="False"

也尝试将它放在 View Cell 中,但这会导致按钮和点击事件不起作用。

【问题讨论】:

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

安卓:

我为 ListView 创建了一个自定义渲染器并设置了

Control.SetSelector(Android.Resource.Color.Transparent);

iOS:

我创建了一个自定义 ViewCell 渲染器并设置了

cell.SelectionStyle = UITableViewCellSelectionStyle.None;

参考资料:

安卓:Xamarin.Forms untappable ListView (remove selection ripple effect)

iOS:https://montemagno.com/adding-a-disclosure-indicator-accessory-to/

【讨论】:

  • 学习如何使用代码部分肯定会以最小的开销改善你的答案。
【解决方案2】:

你可以试试这样的,

myListView.ItemTapped += (object sender, ItemTappedEventArgs e) => {    
   if (e.Item == null) return;     
    ((ListView)sender).SelectedItem = null; 
 }; 

【讨论】:

  • 它仍然突出显示一秒钟,如果按住它会保持突出显示
  • 我使用了“Control.SetSelector(Android.Resource.Color.Transparent);”对于似乎可以工作的android
  • 太棒了!我没有做太多 xamarin,我正在帮助你解决现有的答案
  • 只需要找到一个 iOS 修复程序
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多