【发布时间】:2015-08-29 10:46:00
【问题描述】:
我在 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)
}
};
取自this guide 第13页。
但是,当我添加一个列表视图(详细here)时,
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>'
【问题讨论】:
-
如果你把你的 lambda 放在
new Func<object>( ... )里面会怎样? -
@cubrr 好的,我已将我的所有 ListView 代码包装在
new Func<object> (delegate { ...//all my code//...})中,并已从该错误中继续,但现在收到Not all code paths return a value in anonymous method of type 'System.Func<object>'错误? -
用代码更新你的问题。
-
@cubrr 请见上文
-
啊,对不起,我的意思是,如果你可以添加你现在拥有的实际代码,就会给你错误。