jmd*_*ess 4 xaml android collectionview xamarin.forms
请参阅下面的我的数据模型和 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; }
}
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
外部和内部集合视图的快照:
我强调了颜色,以便更好地看到未缩小的布局。
问题:(我尝试了多种配置但没有解决)
您应该将 StackLayout 与 BindableLayout 结合使用,而不是使用 CollectionView。我刚刚遇到了同样的问题,最后我使用 StackLayout 内部的 BindableLayout 解决了问题,如下所示:
为了给出更好的想法,我在父级中有一些对象列表。像这样的东西:
Customers (Items in the code)
--- Products
------- Batches
-----------Series
Run Code Online (Sandbox Code Playgroud)
因此,我有一个客户列表,其中包含一个产品列表,其中每个产品都包含一个批次列表,最后他们有一个序列列表。
Customers (Items in the code)
--- Products
------- Batches
-----------Series
Run Code Online (Sandbox Code Playgroud)
效果真的很好。
| 归档时间: |
|
| 查看次数: |
3926 次 |
| 最近记录: |