2017-10-03 3 views
0

J'ai trouvé une erreur lorsque vous sélectionnez un élément tous les arrière-plans des enfants sont modifiés pour la même couleur.Xamarin Forms - Listview sur l'élément sélectionné changer tout l'arrière-plan à la même

Dans tous les éléments, j'ai mis la propriété BackgroundColor. Cela ne se est passé dans l'iOS

Suivez l'exemple du code:

XAML

<ListView 
     x:Name="ListPainel" 
     SeparatorColor="#d2d8e2" 
     SeparatorVisibility="Default" 
     Margin="0" 
     ItemsSource="{Binding ListPainel_Source}" 
     HasUnevenRows="true" 
     RefreshCommand="{Binding ListPainel_RefreshCommand}" 
     IsRefreshing="{Binding ListPainel_IsRefreshing}" 

    > 
    </ListView> 

Une partie de ViewCell

 protected override void OnBindingContextChanged() 
    { 
     base.OnBindingContextChanged(); 

     dynamic temp = BindingContext; 

     PainelDto painel = (PainelDto)temp; 

     ... 

     if(painel.HasDetalhes) 
     { 
      Button detalhes = new Button() 
      { 
       Text="VER DETALHES", 
       FontSize = 12, 
       TextColor = Color.FromHex("#4482ff"), 
       HorizontalOptions = LayoutOptions.End, 
       VerticalOptions = LayoutOptions.Start, 
       HeightRequest = 20, 
       WidthRequest = 120, 
       BackgroundColor = Color.DeepPink 
      }; 
      detalhes.SetBinding(
       Button.CommandProperty 
       , new Binding(
        "ViewDetalhesCommand" 
        , BindingMode.Default 
        , null 
        , null 
        , null 
        , _viewModelPainel 
       ) 
      ); 
      box.Children.Add(detalhes); 
     } 

     ... 

     View = box; 
    } 

Unselected article Unselected

élément sélectionné Selected

Quelqu'un sait comment résoudre ce problème?

+0

je change la question. –

Répondre

1

Il s'agit du comportement par défaut lors de la sélection d'une cellule dans iOS. Nous avons besoin d'un custom renderer pour ViewCell pour désactiver l'effet.

Créez une classe appelée NativeiOSCellRenderer dans le projet iOS.

code:

[assembly: ExportRenderer(typeof(ViewCell), typeof(NativeiOSCellRenderer))] 
namespace FormsListViewSample.iOS 
{ 
    class NativeiOSCellRenderer : ViewCellRenderer 
    { 
     public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) 
     { 
      UITableViewCell cell = base.GetCell(item, reusableCell, tv); 
      cell.SelectionStyle = UITableViewCellSelectionStyle.None; 
      return cell;  
     } 
    } 
}