我尝试使用Forms Lab中的GridView。问题是我没有在屏幕上显示任何内容。有一点需要注意 - 当我设置Content = gridView或Content = mainLayout时,我得到空指针引用异常,但我无法找出哪个元素为null。以下是代码中的代码:
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 :(得分:0)
您正在测试哪个平台?这是一个非常alpha的版本,有一些问题,特别是ItemTemplate。
尝试其中一个演示ViewCells,看看它是否适合你......然后从那里开始。
有一件事是行不通的,就是在模板上的布局中放置一个布局。例如,如果您正在使用网格,并且在网格内部,您有一个堆叠面板,而堆叠面板的内容将不会显示,那么我们还不知道如何修复。