我有一台ListView和一台CollectionView (XAM4 pre-8 )。我添加的ListView是为了证明项目显示。绑定显示正确,并且我已经将XAM4添加到所有项目中。未显示CollectionView。为什么?
AppDelegate:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.SetFlags("CollectionView_Experimental");
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}内容页:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:RecipeTonight.Mobile.ViewModels"
x:Class="RecipeTonight.Mobile.Views.WelcomePage"
NavigationPage.HasNavigationBar="False"
>
<ContentPage.Content >
<StackLayout VerticalOptions="CenterAndExpand"
Margin="20"
BackgroundColor="#e9e9e9"
>
<Label Text="Hello World" />
<CollectionView ItemsSource="{Binding RecipeList}" >
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
Text="Test"
FontAttributes="Italic"
VerticalOptions="End" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<ListView ItemsSource="{Binding RecipeList}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Height="40">
<Label Text="{Binding Title}"></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
我在屏幕上看到

发布于 2019-04-24 23:59:40
@Jason是正确的。设置高度
发布于 2020-06-15 04:24:59
对我来说,这个错误更常见,但这是我在搜索帮助时找到的第一个页面,所以也许我的解决方案对某些人有用:
不要忘记在代码隐藏中将ItemSource设置为public。
即
//XAML
<CollectionView ItemsSource="{Binding RecipeList}" >
...etc
//C#
public List<RecipeItem> RecipeList {get; set;} // <---- PUBLIC!发布于 2020-04-11 16:01:16
在我的例子中,问题是我拼写错了属性的名称(即,我使用了所有大写的属性名称)。与ListView不同,CollectionView在项目之间没有行来告诉你有什么东西在那里。
https://stackoverflow.com/questions/55747072
复制相似问题