Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms TableView in XAML

Can anyone tell me how to set up a TableView in XAML please. Tried -

<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="XYZ.Forms.HardCodedCells">
    <ContentPage.Content>
    <StackLayout>
    <Label Text="Above TableView"></Label>
    <TableView>
        <TableRoot>
            <TableSection Title="Test">     
                <TextCell Text="Test"></TextCell>
            </TableSection>
        </TableRoot>
    </TableView>
    </StackLayout>
    </ContentPage.Content>
</ContentPage>

This "attempt" renders blank on screen?

And if I add extra cells, say an EntryCell, to the TableSection I get -

"Object type Xamarin.Forms.TextCell cannot be converted to target type: Xamarin.Forms.View"

As an aside , where can I see the valid XAML syntax for each Forms element?

like image 483
WickedW Avatar asked Jun 24 '14 15:06

WickedW


1 Answers

I should not have used TableRoot but TableView.Root

As an aside, here is the correct code and also how you can drop in a custom cell directly in the tableview XAML.

<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="XYZ.Forms.HardCodedCells">
    <ContentPage.Content>
    <StackLayout>
    <Label Text="Above TableView"></Label>
    <TableView>
        <TableView.Root>
            <TableSection Title="Test">     
                <EntryCell Label="EntryCell"></EntryCell>
                <TextCell Text="Test"></TextCell>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Orientation="Horizontal" >
                        <BoxView Color="Red"></BoxView>
                        <StackLayout>
                            <Label Text="News Item 1"></Label>
                            <Label Text="News URL 1"></Label>
                        </StackLayout>
                        <BoxView x:Name="boxView" Color="Blue" ></BoxView>
                        </StackLayout>      
                    </ViewCell.View>
                </ViewCell>
            </TableSection>
        </TableView.Root>
    </TableView>
    </StackLayout>
    </ContentPage.Content>
</ContentPage>
like image 59
WickedW Avatar answered Sep 24 '22 17:09

WickedW