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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With