首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CollectionView Xamarin未显示

CollectionView Xamarin未显示
EN

Stack Overflow用户
提问于 2019-04-18 21:27:48
回答 3查看 2.8K关注 0票数 2

我有一台ListView和一台CollectionView (XAM4 pre-8 )。我添加的ListView是为了证明项目显示。绑定显示正确,并且我已经将XAM4添加到所有项目中。未显示CollectionView。为什么?

AppDelegate:

代码语言:javascript
复制
        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);
    }

内容页:

代码语言:javascript
复制
<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>

我在屏幕上看到

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-24 23:59:40

@Jason是正确的。设置高度

票数 -1
EN

Stack Overflow用户

发布于 2020-06-15 04:24:59

对我来说,这个错误更常见,但这是我在搜索帮助时找到的第一个页面,所以也许我的解决方案对某些人有用:

不要忘记在代码隐藏中将ItemSource设置为public。

代码语言:javascript
复制
//XAML

<CollectionView ItemsSource="{Binding RecipeList}" >
     ...etc



//C#

public List<RecipeItem> RecipeList {get; set;} // <---- PUBLIC!
票数 1
EN

Stack Overflow用户

发布于 2020-04-11 16:01:16

在我的例子中,问题是我拼写错了属性的名称(即,我使用了所有大写的属性名称)。与ListView不同,CollectionView在项目之间没有行来告诉你有什么东西在那里。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55747072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档