10

谁能告诉我如何在 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 语法?

4

1 回答 1

20

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>
于 2014-06-24T17:07:17.493 回答