2014-08-28 56 views
0

我想從Forms Lab中使用GridView。問題是我沒有在屏幕上顯示任何內容。有一點要注意 - 當我設置Content = gridView或Content = mainLayout時,我得到空指針引用異常,但我找不到哪個元素爲null。這裏的代碼在視圖中:Xamarin Forms Labs GridView沒有顯示

  var itemTemplate = new DataTemplate(typeof (MedicineBoxItemCell)); 
      var gridView = new GridView(); 
      gridView.ItemsSource = medicineBoxViewModel.MedicineBoxViewModelItems; 

     gridView.ItemTemplate = itemTemplate; 

     StackLayout mainLayout = new StackLayout(); 

     mainLayout.Children.Add(gridView); 

     var scrollView = new ScrollView() 
     { 
      Content = mainLayout, 
      BackgroundColor = Color.Yellow 
     }; 

     Content = scrollView; 
    } 
    public class MedicineBoxItemCell : ViewCell 
      { 
       public MedicineBoxItemCell() 
       { 
        var name = new Entry() 
        { 
         HorizontalOptions = LayoutOptions.FillAndExpand 
        }; 
        name.SetBinding(Entry.TextProperty, "MedicineBoxItem.Medicine.Name"); 
        View = name; 
       } 
      }`  

回答

0

你在測試什麼平臺?這是一個非常alpha的版本,它有一些問題,特別是ItemTemplate。

嘗試其中一個演示ViewCells,看看它是否適用於你..並從那裏去。

有一件事情是不行的,就是在模板的佈局裏面有佈局。例如,如果您使用的是網格,並且在網格內部有一個可用於堆疊面板的堆疊面板,並且它的內容不會出現,那麼我們不知道如何修復。

+0

我在Android上測試。 即使當我嘗試網格單元格是TextCell類型它不起作用。 基本問題是,我無法將GridView添加到Page的內容。 內容= gridView拋出零點異常 – 2014-08-29 08:27:42

+0

它沒有在android中實現..但使用模板有問題.. 我們需要幫助在那裏隨時提供您的輸入: https://github.com/的XForms/Xamarin-表單實驗室 – 2014-08-29 14:45:09