gpt4 book ai didi

android - 嵌套的 CollectionViews 和显示(使用 Visual Studio 2019、Xamarin XPlatform Android)

转载 作者:行者123 更新时间:2023-12-04 16:02:27 25 4
gpt4 key购买 nike

  1. 嵌套的 CollectionView 滚动到另一个:官方支持吗?
  2. 显示这些集合问题

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

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>

外部和内部 Collection View 的快照:

enter image description here

我强调了颜色以更好地查看未缩小的布局。

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

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

最佳答案

您应该将 StackLayout 与 BindableLayout 一起使用,而不是使用 CollectionView。我刚刚遇到了同样的问题,最后我使用 StackLayout 中的 BindableLayout 解决了如下问题:

enter image description here

为了更好地理解,我在父对象中有一些对象列表。像这样的:

Customers (Items in the code)
--- Products
------- Batches
-----------Series

所以我有一个客户列表,其中包含一个产品列表,其中每个都包含一个批处理列表,最后他们有一个序列列表。

<ScrollView>
<StackLayout BindableLayout.ItemsSource="{Binding Items}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">

<StackLayout x:DataType="ms:Customer" Orientation="Vertical">

<StackLayout BindableLayout.ItemsSource="{Binding Products}">
<BindableLayout.ItemTemplate>
<DataTemplate>

<Frame CornerRadius="10" Margin="5, 5, 5, 5" HasShadow="True" BackgroundColor="#5ac8fa">
<StackLayout>

<StackLayout x:DataType="ms:Product" Orientation="Vertical">
<Label Text="{Binding Name}" FontAttributes="Bold" FontSize="Caption" />
<Label Text="{Binding ProductCode}" FontAttributes="Italic" FontSize="Micro" />

<StackLayout BindableLayout.ItemsSource="{Binding Batches}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout x:DataType="ms:Batch" Orientation="Vertical" HorizontalOptions="FillAndExpand">

<Grid Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding Code}" FontAttributes="Bold" FontSize="Caption" />
<Label Grid.Column="1" Text="{Binding ExpiredDateFormated}" FontAttributes="Italic" HorizontalTextAlignment="End" FontSize="Micro" />
</Grid>

<StackLayout BindableLayout.ItemsSource="{Binding Serials}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout x:DataType="ms:Serial" Orientation="Vertical" HorizontalOptions="FillAndExpand">
<Frame CornerRadius="10" HasShadow="True">

<StackLayout>
<Label Text="{Binding SerialCode}" FontAttributes="Bold" FontSize="Micro" />
</StackLayout>
<Frame.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:SearchSerialsByLocationViewModel}}, Path=SerialTappedCommand}"
CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
</Frame>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>

</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>

</StackLayout>

</StackLayout>
</Frame>

</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>

</StackLayout>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>

效果很好。

enter image description here

关于android - 嵌套的 CollectionViews 和显示(使用 Visual Studio 2019、Xamarin XPlatform Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55787805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com