2017-02-01 44 views
0

这看起来像是一个非常原始的问题,应该通过更改属性来解决。但这是我的问题:Xamarin Forms Listview disbale cell highlight

  • 用户从列表视图中选择一个单元格。
  • 我重写单元格的背景颜色,并将其设置为适当的颜色(我们有不同的颜色主题)。
  • 当我回到我的列表视图,并再次选择相同的项目时,单元格会运行与以前相同的代码,但突出显示的颜色是默认值。

我看到的唯一方法之一是NOTSelectedItem设置为null。我这样做,因为如果我不这样做,我回到我的列表视图,我不能选择相同的项目。

你会认为Xamarin在列表视图HighlightCellSelection上有一个属性,我可以将其设置为false。任何人都可以解决这个问题?

这里是我的代码:

ListView.ItemSelected += (s, e) => 
       { 
        ((ListView)s).BackgroundColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.Black : Xamarin.Forms.Color.White; 
        XamarinMobile.ViewModels.GridCellViewModel cell = (XamarinMobile.ViewModels.GridCellViewModel)e.SelectedItem; 
        ((ListView)s).SelectedItem = null; 
       } 
我结合上下文,它做同样的事情

另外:

this.Tapped += (s, e) => { 
     this.View.BackgroundColor = App.IsDarkThemeEnabled() ? Xamarin.Forms.Color.Black : Xamarin.Forms.Color.White; 
    }; 

回答

0

基本上发生了什么事情是该属性没有得到设置,如果我把它设置为我以前所做的一样。通过简单地将其更改为transparent,然后选择所需的颜色即可解决问题。

0

我假设这是iOS上,但如果我理解正确你的问题并且您想要执行的操作是禁用默认单元格高亮显示,则可以创建ViewCellRenderer并更改单元格选择样式。

public class ViewCellRenderer : Xamarin.Forms.Platform.iOS.ViewCellRenderer 
{ 
    public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) 
    { 
     var cell = base.GetCell(item, reusableCell, tv); 
     cell.SelectionStyle = UITableViewCellSelectionStyle.None; 
     cell.BackgroundColor = UIColor.Clear; 
     return cell; 
    } 
}