【问题标题】:Xamarin Forms TableView in XAMLXamarin 在 XAML 中形成 TableView
【发布时间】:2014-08-14 22:34:12
【问题描述】:

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

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    我不应该使用 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>
    

    【讨论】:

    • @StephaneDelcroix 和发帖者:所以当我只想要带有某些部分的TableView 时,我对使用正确的 XAML 感到困惑。我应该做&lt;TableView&gt;&lt;TableView.Root&gt;&lt;TableRoot&gt; 还是不需要&lt;TableRoot&gt; 部分还是不需要&lt;TableView.Root&gt; 部分?
    • 嗨@hvaughan3 - 我还没有重新访问 Xamarin Forms,因为我在很早的 V1 时写了这篇文章 - 现在可以查阅这些“更新”文档 - developer.xamarin.com/guides/cross-platform/xamarin-forms/…
    猜你喜欢
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多