2014-06-24 45 views
9

任何人都可以告诉我如何在XAML中设置TableView。试过 -Xamarin在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> 

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

如果我增加额外的电池,说的EntryCell,到TableSection我得到 -

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

另外,我可以在哪里看到每个Forms元素的有效XAML语法?

回答

17

我不应该使用TableRootTableView.Root

顺便说一句,这里是正确的代码,以及如何可以在自定义单元格,直接在实现代码如下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> 
+0

@StephaneDelcroix和海报:所以我很困惑正确的XAML使用时,我只是想与一些部分的“TableView”。我应该做''或者我不需要''部分,还是我不需要''部分? – hvaughan3

+0

hi @ hvaughan3 - 我还没有重新访问过Xamarin Forms,因为当我写这篇文章的时候很早V1 - 也许现在请查阅这些“更新”的文档 - http://developer.xamarin.com/guides/cross-platform/xamarin-形式/用户界面/的tableview / – WickedW