Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示Xamarin';StackLayout内不同来源的s CollectionView项未正确显示_Xamarin_Collectionview_Stacklayout - Fatal编程技术网

显示Xamarin';StackLayout内不同来源的s CollectionView项未正确显示

显示Xamarin';StackLayout内不同来源的s CollectionView项未正确显示,xamarin,collectionview,stacklayout,Xamarin,Collectionview,Stacklayout,我正在使用Xamarin的CollectionView和Stacklayout,并试图以集合视图的形式显示来自不同来源的项目列表。然而,下面显示的代码输出是我没有预料到的。第一个集合视图的结果显示在一个小窗口中,所有剩余的项目都可以通过滚动读取。但是,我希望在不使用滚动条的情况下显示它们,如果代码中添加了更多CollectionView,那么同样的功能也会发挥作用。这里有我遗漏的东西吗 <?xml version="1.0" encoding="UTF-8"?> <Conten

我正在使用Xamarin的CollectionView和Stacklayout,并试图以集合视图的形式显示来自不同来源的项目列表。然而,下面显示的代码输出是我没有预料到的。第一个集合视图的结果显示在一个小窗口中,所有剩余的项目都可以通过滚动读取。但是,我希望在不使用滚动条的情况下显示它们,如果代码中添加了更多CollectionView,那么同样的功能也会发挥作用。这里有我遗漏的东西吗

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             Title="Arhoo"
             x:Class="Arhoo.Pages.MainFeedPage">

        <StackLayout>
            <StackLayout VerticalOptions="FillAndExpand">                
                <CollectionView x:Name="ItemsListView" 
                        ItemsSource="{Binding Hotels}" 
                        VerticalOptions="FillAndExpand" Margin="10" Visual="Material">

                    <CollectionView.Header>
                        <StackLayout BackgroundColor="LightGray" HeightRequest="50" >
                            <Label Visual="Material" Text="Hotels" FontSize="Medium" FontAttributes="Bold" />
                        </StackLayout>
                    </CollectionView.Header>
                    <CollectionView.ItemsLayout>
                        <GridItemsLayout Orientation="Vertical"  Span="2"/>
                    </CollectionView.ItemsLayout>
                    <CollectionView.EmptyView>
                        <StackLayout>
                            <Label HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="Loading Hotels"/>
                        </StackLayout>
                    </CollectionView.EmptyView>
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout Visual="Material">
                                <ContentView Padding="10">
                                    <Frame HasShadow="false" OutlineColor="#2f2f2f" Padding="0" CornerRadius="2">
                                        <Grid BackgroundColor="#f2f2f2" MinimumHeightRequest="400">
                                            <Image Source="{Binding Image}" Aspect="AspectFill"/>
                                            <BoxView BackgroundColor="#000000" Opacity="0.4"/>
                                            <Label Text="{Binding Text}" Margin="15" TextColor="White" VerticalOptions="End"
                                       VerticalTextAlignment="End" LineBreakMode="NoWrap" FontSize="18" />
                                        </Grid>
                                    </Frame>
                                </ContentView>
                            </StackLayout>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>

            </StackLayout>            
            <StackLayout VerticalOptions="FillAndExpand">

                <CollectionView x:Name="TOsListView" 
                        ItemsSource="{Binding TourOperators}" 
                        VerticalOptions="FillAndExpand" >
                    <CollectionView.Header>
                        <StackLayout BackgroundColor="LightGray" HeightRequest="20" >
                            <Label Margin="10,0,0,0" Text="Tour Operators" FontSize="Medium" FontAttributes="Bold" />
                        </StackLayout>
                    </CollectionView.Header>
                    <CollectionView.ItemsLayout>
                        <GridItemsLayout 
                    Orientation="Vertical"
                    Span="2"/>
                    </CollectionView.ItemsLayout>
                    <CollectionView.EmptyView>
                        <StackLayout>
                            <Label 
                        HorizontalOptions="CenterAndExpand"
                        VerticalOptions="CenterAndExpand"
                        Text="Loading TOs"/>
                        </StackLayout>
                    </CollectionView.EmptyView>
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <ContentView Padding="10" >
                                <Frame HasShadow="false"
                               OutlineColor="#2f2f2f"
                               Padding="0"
                               CornerRadius="2">
                                    <Grid BackgroundColor="#f2f2f2">

                                        <Image Source="{Binding Image}"
                                       Aspect="AspectFill"/>

                                        <BoxView BackgroundColor="#000000"
                                         Opacity="0.4"/>

                                        <Label Text="{Binding Text}"
                                       Margin="15"
                                       TextColor="White"
                                       VerticalOptions="End"
                                       VerticalTextAlignment="End"
                                       LineBreakMode="NoWrap" 
                                       FontSize="18" />
                                    </Grid>
                                </Frame>
                            </ContentView>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
            </StackLayout>
        </StackLayout> 



</ContentPage>

我已经在我的代码中添加了一个
,并且collectionview项目显示为我想要的。这是为我工作的修改过的代码

  ?xml version="1.0" encoding="UTF-8"?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 Title="Arhoo" 
                 x:Class="Arhoo.Pages.MainFeedPage">
        <ScrollView>
            <StackLayout>  
           <CollectionView x:Name="HotelsListView" ... </CollcetionView>
</StackLayout>
<StackLayout>  
           <CollectionView x:Name="HotelsListView" ... </CollcetionView>
</StackLayout>
<StackLayout>  
           <CollectionView x:Name="HotelsListView" ... </CollcetionView>
</StackLayout>
</StackLayout>

    </ScrollView>

</ContentPage>
?xml version=“1.0”encoding=“UTF-8”>

显示问题的屏幕截图将非常有用helpful@Semytech,根据您的代码,页面内容中有两个collectionview,您的意思是要为两个collectionview显示不带scrollview的所有项目?如果collectionview中有许多项目,我认为这是不可能的。@CherryBu MSFT是的,我想在collectionview中显示内容而不滚动。当然,我将限制每个collectionview中的项目数量,比如6个,并在内容页中完全显示它们,而不滚动。