2017-08-24 4 views
0

私は次のように設定されているテーブルビューを持っている:ViewCellをTableViewに追加しましたが、ViewCellの高さを設定できませんか?

<ContentPage.Content> 
    <TableView x:Name="tableView" Intent="Settings" HasUnevenRows="True"> 
    </TableView> 
</ContentPage.Content> 

私は、このViewCellを追加し、C#のバッキングコードで、私は、テキストを追加、バックエンドのコード

var newSection = new TableSection("Choose Categories"); 
     foreach (var category in categories) 
     { 
      var cell = new CategoryViewCell 
      { 
       BindingContext = category 
      }; 
      cell.SelectedOrToggled += selectCategory; 
      newSection.Add(cell); 
     } 
     // I want to set the height of TableViewFooter to 200 but 
     // it does not happen. I just see a row colored red that 
     // is the same height as all the other rows. 
     var cmt = new TableViewFooter(
      "Select a Category and all cards from that category will be added to the deck", 
      200); 
     newSection.Add(cmt); 
     return newSection; 

でTextCellsを追加高さを設定します。

<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="Japanese.TableViewFooter"> 
    <Grid 
     BackgroundColor="Red" 
     x:Name="_containerGrid" 
     VerticalOptions="CenterAndExpand" 
     Padding="20,10"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" /> 
     </Grid.ColumnDefinitions> 
     <Label 
      x:Name="_commentLbl" 
      Style="{DynamicResource ListItemDetailTextStyleStyle}" 
      TextColor="#59595F" 
      HorizontalOptions="FillAndExpand" 
      VerticalOptions="CenterAndExpand" /> 
    </Grid> 
</ViewCell> 

public partial class TableViewFooter : ViewCell 
{ 
    public TableViewFooter(string text, double height) 
    { 
     InitializeComponent(); 
     _commentLbl.Text = text; 
     _commentLbl.HeightRequest = height; 
     _containerGrid.HeightRequest = height; 
    } 
} 

しかし、私は何をすべきかに関係なくはViewCell(タイプTableViewFooter)の高さは、まだ他の行の高さと同じままです。

HasUnevenRows = "True"に設定しようとしましたが、これは効果がないようです。

私が追加した最後のViewCell(タイプTableViewFooter)の高さを変更することはできますか?

+0

私はあなたがおそらくを見て、高さを調整するレンダラが必要になると思いますここで:https://forums.xamarin.com/discussion/2889/setting-table-cell-height-after-binding –

+0

section.Add(新しいCustomViewCell {高さ= 100});うまくいかない? –

+0

高さを200(2番目のパラメータ)に設定しようとしていますが、機能しません。 –

答えて

1

この回避策を試してください:

public TableViewFooter(string text, double height) 
{ 
    InitializeComponent(); 
    _commentLbl.Text = text; 
    Height = height; 
} 

とViewCellののXmaIでグリッドにこの行を削除します。

VerticalOptions="CenterAndExpand" 
+0

こんにちはコール、私が問題があるのは、TableViewFooterの高さです。 –

+0

@は、TableViewFooterの初期コンストラクタのコードを添付することができます。 –

+0

こんにちは、添付されています。 –