我正在使用Xamarin.Forms,尝试创建一个包含ListView
的弹出窗口。
我正在尝试使用以下结构:
var PopUp = new StackLayout
{
BackgroundColor = Color.Black, // for Android and WP
Orientation = StackOrientation.Vertical,
Children =
{
PLZOrt_Label, // my Label on top
SearchBarPLZOrt, // my SearchBar to the ListView
LVPLZOrt, // The Listview (all Cities/Zip-Codes in the Datasource -> List)
}
};
取自这篇指南第13页。
然而,当我添加一个列表视图(如此处所述),
new Func<object> (delegate {
ListView listView = new ListView {
// Source of data items.
ItemsSource = devices,
ItemTemplate = new DataTemplate(() =>
{
// Create views with bindings for displaying each property.
Label nameLabel = new Label();
nameLabel.SetBinding(
Label.TextProperty, "{Binding Name, Converter={StaticResource strConverter}}"
);
Label IDLabel = new Label();
IDLabel.SetBinding(
Label.TextProperty, "{Binding Path=ID, Converter={StaticResource guidConverter}}"
);
return new ViewCell
{
View = new StackLayout
{
})
});
"ItemTemplate"这行代码报错:"无法将 Lambda 表达式转换为类型 'System.Type',因为它不是委托类型"
在其他一些类似的问题中,解决方法似乎是添加一个
new action(() => {})
结构,但由于这是 Xamarin 批准的方法,所以我不确定为什么需要实现这个方法?谢谢!
编辑: 添加了顶部func行之后,我现在得到了一个错误,该错误引发在该行上:
Error CS1643: Not all code paths return a value in anonymous method of type 'System.Func<object>'
new Func<object>(...)
里面会怎样? - cbrnew Func<object> (delegate { ...//所有我的代码//...})
包装了我的所有 ListView 代码,并且已经解决了那个错误,但现在出现了一个Not all code paths return a value in anonymous method of type 'System.Func<object>'
错误? - George Edwards