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;
}
}`
我在Android上測試。 即使當我嘗試網格單元格是TextCell類型它不起作用。 基本問題是,我無法將GridView添加到Page的內容。 內容= gridView拋出零點異常 – 2014-08-29 08:27:42
它沒有在android中實現..但使用模板有問題.. 我們需要幫助在那裏隨時提供您的輸入: https://github.com/的XForms/Xamarin-表單實驗室 – 2014-08-29 14:45:09