嵌套的CollectionViews和显示(使用Visual Studio 2019,Xamarin XPlatform Android) [英] Nested CollectionViews and display (with Visual Studio 2019, Xamarin XPlatform Android)

查看:84
本文介绍了嵌套的CollectionViews和显示(使用Visual Studio 2019,Xamarin XPlatform Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 嵌套CollectionView并在其中滚动一个:正式支持吗?
  2. 显示这些收藏夹问题

请参见下面的数据模型和XAML代码(我没有网站可以放置生成的屏幕图像)

See below my data model and the XAML code (I have no site to put the resulting screen image in)

namespace Notes.Models
{
    public class Note
    {
        public enum NoteStatus { suspended, alive }

        public string       Description { get; set; }
        public NoteStatus   Status { get; set; }
    }

    public class NotesContainer
    {
        public string                       Name { get; set; }
        public DateTime                     LastModified { get; set; }
        public ObservableCollection<Note>   ListOfNotes { get; set; }
    }
}

  <CollectionView x:Name="notesContainers" SelectionMode="Single" EmptyView="No items currently exist !">
    <CollectionView.ItemTemplate>
      <DataTemplate>
        <Frame BorderColor="Red" BackgroundColor="Beige" CornerRadius="3" HasShadow="False" Padding="5">
          <StackLayout BackgroundColor="Aqua" Padding="5">
            <Grid>
              <Grid.RowDefinitions><RowDefinition Height="auto"/><RowDefinition Height="auto"/></Grid.RowDefinitions>
              <Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions>
              <Label Grid.RowSpan="2" Text="{Binding Name}" VerticalTextAlignment="Center" FontSize="Large"/>
              <Label Grid.Row="0" Grid.Column="1" Text="{Binding LastModified, StringFormat='\{0:dddd dd}'}" HorizontalTextAlignment="End"/>
              <Label Grid.Row="1" Grid.Column="1" Text="{Binding LastModified, StringFormat='\{0:MMMM yyyy}'}" HorizontalTextAlignment="End"/>
            </Grid>
            <StackLayout BackgroundColor="BlueViolet" Padding="10">
              <CollectionView ItemsSource="{Binding ListOfNotes}" SelectionMode="Single" EmptyView="No items currently exist !">
                <CollectionView.ItemTemplate>
                  <DataTemplate>
            <StackLayout BackgroundColor="Coral" Padding="0,3">
                    <Frame BorderColor="Blue" BackgroundColor="LightBlue" CornerRadius="3" HasShadow="False" Padding="5">
                      <StackLayout Orientation="Horizontal">
                        <Label Text="{Binding Description}" HorizontalOptions="Start" VerticalTextAlignment="Center"/>
                        <Label Text="{Binding Status}" HorizontalOptions="EndAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="End"/>
                      </StackLayout>
                    </Frame>
             </StackLayout>
                 </DataTemplate>
                </CollectionView.ItemTemplate>
              </CollectionView>
            </StackLayout>
          </StackLayout>
        </Frame>
      </DataTemplate>
    </CollectionView.ItemTemplate>
  </CollectionView>

外部&的快照内部collectionviews:

snapshot of outer & inner collectionviews:

我强调了颜色以更好地看到布局没有缩小.

I accented the colors to better see the layouts not shrinked.

问题:(我尝试了多种配置,但没有解决方案)

Questions : (I have tried multiple configurations but without solution)

  1. 如何将StackLayouts缩小到其内容?
  2. 为什么StackLayouts会拉长屏幕的尺寸?

推荐答案

嵌套CollectionView并在其中滚动一个:正式支持吗?

Nested CollectionView with scrolling one inside another : is it officially supported ?

据我所知,并不是所有平台都支持嵌套的 CollectionViews ,因为它们中都有Scroll,而嵌套的 ScrollViews 是众所周知的坏习惯.

In my knowledge, nested CollectionViews are not supported by all platforms as they have a Scroll in them and Nested ScrollViews are a widely known bad practice.

显示这些收藏夹问题

Display these collections problem

我无法理解您在这里的确切含义,但是如果您能澄清一下,也许我可以为您提供帮助.

I was not able to understand what exactly did you mean here but if you could clarify, maybe I would be able to help you out.

如何将 StackLayouts 缩小到其内容?

通过将 Spacing 设置为0,将是一个不错的开始!

By setting the Spacing to 0 would be a good start!

我希望StackLayouts不会超过屏幕的大小,就像上面的代码和一些数据一样

I expect StackLayouts no longer than the size of the screen as it is with the code above and a few data

您的StackLayout是否占据了整个屏幕?( ItemTemplate 中的那个?)

Is it that your StackLayout taking the whole screen? (The one which is in the ItemTemplate?)

这篇关于嵌套的CollectionViews和显示(使用Visual Studio 2019,Xamarin XPlatform Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆