2016-07-22 25 views
0

目前我有一個自定義的ViewCell綁定到一個ObservableCollection模板選擇器。 我將自定義單元格模板綁定到我的Xamarin.Forms IOS ListView。Xamarin.Forms ListView與CustomViewCell禁用選定的項目顏色

我的問題是,我不能禁用所選項目的突出,如果我通過MenuContext操作複製所選項目的灰色顏色只出現....

伊夫想盡自定義呈現,我發現上互聯網:)即時放棄似乎是我不能解決這個問題也許有人可以給我一些信息。

也許即時通訊使用錯誤的自定義渲染器。我是否需要渲染器來解決這個問題?

ViewCellRenderer

[assembly: ExportRenderer(typeof(GerätViewCell), typeof(NativeViewCellRenderer))] 
namespace LindeXF.iOS.Renderer { 

    public class NativeViewCellRenderer : ViewCellRenderer { 

     public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) { 
      var cell = base.GetCell(item, reusableCell, tv); 
      if (cell != null) 
       cell.SelectionStyle = UITableViewCellSelectionStyle.None; 

      return cell; 
     } 
    } 
} 

定製ViewCell

<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="LindeXF.Core.CustomTemplates.GerätViewCell" 
      > 
    <ViewCell.ContextActions> 
    <MenuItem x:Name="MenuItemDuplizieren" 
       CommandParameter="{Binding Id}" 
       Clicked="OnDuplizierenClicked" 
       Text="Duplizieren" /> 
    <MenuItem x:Name="MenuItemLöschen" 
       CommandParameter="{Binding Id}" 
       Clicked="OnLöschenClicked" 
       Text="Löschen" 
       IsDestructive="True" /> 
    </ViewCell.ContextActions> 
    <Grid ColumnSpacing="0" BackgroundColor="White"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="40"/> 
     <ColumnDefinition Width="9*"/> 
     <ColumnDefinition Width="7*"/> 
     <ColumnDefinition Width="10*"/> 
     <ColumnDefinition Width="5*"/> 
     <ColumnDefinition Width="18*"/> 
     <ColumnDefinition Width="10*"/> 
     <ColumnDefinition Width="10*"/> 
    </Grid.ColumnDefinitions> 
    <BoxView BackgroundColor="{Binding BoxColor}" Grid.Column="0"/> 
    <Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="1"/> 
    <Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="2"/> 
    <Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="3"/> 
    <Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="4"/> 
    <Label FontSize="14" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="5"/> 
    <Label FontSize="14" HorizontalTextAlignment="End" Margin="0,0,5,0" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="6"/> 
    <Label FontSize="14" HorizontalTextAlignment="End" Margin="0,0,5,0" VerticalTextAlignment="Center" Text="{Binding Test}" Grid.Column="7"/> 
    </Grid> 
</ViewCell> 

的ListView

<ListView x:Name="ListViewKalkulation" 
      Margin="1,0,1,1" 
      ItemTapped="ListViewKalkulationText_OnItemTapped" 
      ItemTemplate="{StaticResource TemplateSelector}" 
      ChildAdded="ListViewKalkulation_OnChildAdded" 
      ItemSelected="ListViewKalkulation_OnItemSelected" 
      SeparatorVisibility="None" 
      BackgroundColor="Silver" 
      Grid.Row="1" /> 

感謝您的時間!

+0

你好,也許你提供有關問題的詳細informtation,將是很好的提你爲什麼要custome渲染你的viewcell。一個用例場景會很好:) – BraveHeart

+0

Hej,對不起,我在想這個問題很明顯:)我只是想禁用列表視圖項目的突出顯示時,與他們進行交互(不會去的醜灰色)我在想這可能是不可能的,因爲即時通訊使用視圖單元格作爲我的Listview項目 –

回答

3

問題不在於你的ViewCell,所以你不需要自定義渲染器來解決你的問題。問題僅僅是由於ListView的行爲。一旦您觸摸ListView中的項目或項目的一部分,ListView將突出顯示該項目,而不管該單元格的內容是否像字符串一樣簡單,或者與您的情況一樣複雜。

解決你的問題,你有兩個選擇

  1. 在後面的代碼處理 當「ListViewKalkulation_OnItemSelected」使用

    ListViewKalkulation.SelectedItem = null; 
    
  2. 如果你想使用客戶渲染器ViewCell ,請嘗試使用我從another solution獲得的代碼,儘管我沒有測試過它。

    public override UITableViewCell GetCell(Cell item, UITableView tv) 
    { 
        var cell = base.GetCell(item, tv); 
    
        cell.SelectedBackgroundView = new UIView { 
         BackgroundColor = UIColor.DarkGray, 
        }; 
    
        return cell; 
    } 
    
+0

對不起,對於遲到的回覆,你在哪裏是正確的!從來沒有想過這個。謝謝你解決了我的問題! –

相關問題