【问题标题】:Collection view in collection view items are not visible集合视图项目中的集合视图不可见
【发布时间】:2021-11-01 05:16:45
【问题描述】:

我有一个问题,我只能从每个列表中看到 4 个项目。我尝试在集合视图上执行 VerticalOptions Fill/FillandExpand 之类的操作,但仍然无法全部看到。尝试在外部集合视图上执行 HeightRequest = 99999 并在内部执行 9999 似乎暴露了这些项目,所以我知道它们“在那里”。但这是解决问题的错误方法

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
         x:Name="AnimeListPagee"
         x:Class="OtakuApp.Pages.AnimeListPage">
<RefreshView x:Name="HomeRefreshView"
             IsRefreshing="{Binding IsBusy}"
             Command="{Binding RefreshCommand}"
             RefreshColor="White"
             BackgroundColor="DodgerBlue">
    <CollectionView ItemsSource="{Binding AnimListsList}"
                            VerticalOptions="Start"
                            BackgroundColor="Transparent"
                            ItemsLayout="VerticalList"
                            SelectionMode="None"
                            x:Name="CollectionView1">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout>
                    <Label Text="{Binding name}" FontSize="30">
                    </Label>
                    <CollectionView ItemsSource="{Binding entries}"
                                            BackgroundColor="Transparent"
                                            VerticalOptions="Start"
                            ItemsLayout="VerticalList"
                            SelectionMode="Single"
                                            SelectedItem="{Binding BindingContext.Entry, Source={x:Reference Name=AnimeListPagee}}"
                            x:Name="CollectionView2">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout>
                                    <Label Text="{Binding media.Title.Romaji}"></Label>
                                    <Label Text="{Binding progress}"></Label>
                                    <Frame BackgroundColor="Green">
                                        <StackLayout>
                                            <Frame BackgroundColor="Yellow" xct:TouchEffect.NativeAnimation="True"
                                                           xct:TouchEffect.Command="{Binding BindingContext.InfoCommand, Source={x:Reference Name=AnimeListPagee}}"></Frame>
                                            <Frame BackgroundColor="Red" xct:TouchEffect.NativeAnimation="True"
                                                           xct:TouchEffect.Command="{Binding BindingContext.InfoCommand2, Source={x:Reference Name=AnimeListPagee}}"></Frame>
                                        </StackLayout>
                                    </Frame>
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</RefreshView>

screenshot

【问题讨论】:

  • 你能发布一个截图来说明问题吗?嵌套 CollectionViews 通常是一个非常糟糕的主意。考虑改用分组。 ScrollView 和 StackLayout 的用途是什么? CollectionView 本质上是可滚动的,因此不需要 ScrollView 并且 StackLayout 没有做任何有用的事情。这可能是您的问题的原因
  • 取得了一些进展。删除滚动视图和堆栈布局后,我可以看到所有列表。但我每个只能看到 4 个项目。这第四个被剪掉了。您可以在屏幕截图的中间看到它。观看列表从上一个列表开始的项目被削减。截图在帖子底部,因为 Stackoverflow 不允许我嵌入图片。
  • 你能把scrollview和stacklayout去掉后的代码给我们看看吗?
  • 我用更新后的代码编辑了帖子
  • 有什么想法吗?

标签: xaml xamarin xamarin.forms mvvm


【解决方案1】:

我在我这边做了一个测试,看起来还不错。你可以看看是不是你想要的。

xmal:

 <CollectionView x:Name="outcollection"
                 >
      <CollectionView.ItemsLayout>
          <LinearItemsLayout Orientation="Vertical"
                             ItemSpacing="0"/>
      </CollectionView.ItemsLayout>
      <CollectionView.ItemTemplate>
          <DataTemplate>
              <StackLayout BackgroundColor="LightBlue"
                           HeightRequest="200">
              <Label Text="{Binding Name}"/>
              <CollectionView x:Name="insidecol" ItemsSource="{Binding peoples}">
                  <CollectionView.ItemTemplate>
                      <DataTemplate>
                          <StackLayout BackgroundColor="LightGreen">
                          <Label Text="{Binding Name}"/>
                              <Label Text="{Binding age}"/>
                              </StackLayout>
                      </DataTemplate>
                  </CollectionView.ItemTemplate>
              </CollectionView>
                      </StackLayout>
          </DataTemplate>
      </CollectionView.ItemTemplate>
  </CollectionView>

型号:

 public class House
    {public string Name { set; get; }
        public string Size { set; get; }
        public List<People> peoples { set; get; }
        public House()
        {
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多