2014-06-24 20 views
9

Bất kỳ ai cũng có thể cho tôi biết cách thiết lập một TableView trong XAML. Đã thử -Bảng biểu mẫu Xamarin Xem trong 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> 
     <TableRoot> 
      <TableSection Title="Test">  
       <TextCell Text="Test"></TextCell> 
      </TableSection> 
     </TableRoot> 
    </TableView> 
    </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

"Lần thử" này hiển thị trống trên màn hình?

Và nếu tôi thêm các tế bào thêm, nói một EntryCell, đến TableSection tôi nhận được -

"kiểu Object Xamarin.Forms.TextCell không thể được chuyển đổi để nhắm mục tiêu loại: Xamarin.Forms.View"

Ngoài ra, tôi có thể thấy cú pháp XAML hợp lệ cho từng phần tử Biểu mẫu ở đâu?

Trả lời

17

tôi không nên sử dụng TableRoot nhưng TableView.Root

Là một sang một bên, đây là mã chính xác và còn làm thế nào bạn có thể thả trong một tế bào tùy chỉnh trực tiếp trong 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> 
     <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 và áp phích: Vì vậy, tôi nhầm lẫn về XAML chính xác được sử dụng khi tôi chỉ muốn 'TableView' với một số phần. Tôi có nên làm '' hay tôi không cần phần '' hay tôi không cần phần ''? – hvaughan3

+0

hi @ hvaughan3 - Tôi chưa xem lại các biểu mẫu Xamarin kể từ khi tôi viết bài này khi nó rất sớm V1 - có thể tham khảo tài liệu "mới hơn" này ngay bây giờ - http://developer.xamarin.com/guides/cross-platform/xamarin- biểu mẫu/giao diện người dùng/tableview / – WickedW

Các vấn đề liên quan