Xamarin在XAML中表示TableView

时间:2014-06-24 15:20:03

标签: xamarin.forms

有谁能告诉我如何在XAML中设置TableView。试过 -

<?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>

这个“尝试”在屏幕上呈现空白?

如果我向TableSection添加额外的单元格,比如说EntryCell,我得到 -

“对象类型Xamarin.Forms.TextCell无法转换为目标类型:Xamarin.Forms.View”

顺便说一下,在哪里可以看到每个Forms元素的有效XAML语法?

1 个答案:

答案 0 :(得分:18)

我不应该使用 TableRoot ,但 TableView.Root

顺便说一下,这里是正确的代码,以及如何直接在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>