Xamarin Forms Labs GridView没有显示
问题描述:
我想从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;
}
}`
答
你在测试什么平台?这是一个非常alpha的版本,它有一些问题,特别是ItemTemplate。
尝试其中一个演示ViewCells,看看它是否适用于你..并从那里去。
有一件事情是不行的,就是在模板的布局里面有布局。例如,如果您使用的是网格,并且在网格内部有一个可用于堆叠面板的堆叠面板,并且它的内容不会出现,那么我们不知道如何修复。
我在Android上测试。 即使当我尝试网格单元格是TextCell类型它不起作用。 基本问题是,我无法将GridView添加到Page的内容。 内容= gridView抛出零点异常 – 2014-08-29 08:27:42
它没有在android中实现..但使用模板有问题.. 我们需要帮助在那里随时提供您的输入: https://github.com/的XForms/Xamarin-表单实验室 – 2014-08-29 14:45:09