0
votes

I have a TableView that is set up as follows:

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

I add TextCells in the back-end code

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;

I then add this ViewCell and in C# backing code I add in text and set the height.

<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;
    }
}

However no matter what I do the height of the ViewCell (type TableViewFooter) still stays the same as the height of the other rows.

I tried setting HasUnevenRows="True" but this seems to have no effect.

Is it possible to change the height of the last ViewCell (type TableViewFooter) that I add?

1
I think you will need a renderer to adjust the height, perhaps take a look at here: forums.xamarin.com/discussion/2889/… - Jordy Dieltjens
does section.Add(new CustomViewCell { Height = 100 }); not work? - ColeX - MSFT
I am trying to set the height to 200 (second param) but doesn't work. - Samantha J T Star

1 Answers

1
votes

Try this workaround :

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

and delete this line in Grid in the XMAL of ViewCell:

VerticalOptions="CenterAndExpand"