Xamarin.forms CollectionView页脚Xamarif表单粘贴到页面底部
我正在使用最新的xamarin forms 4.3中的集合视图,我想知道是否有办法使集合视图的页脚粘到页面底部,即使集合视图中只有很少的项目 这可能吗Xamarin.forms CollectionView页脚Xamarif表单粘贴到页面底部,xamarin.forms,Xamarin.forms,我正在使用最新的xamarin forms 4.3中的集合视图,我想知道是否有办法使集合视图的页脚粘到页面底部,即使集合视图中只有很少的项目 这可能吗 谢谢,CollectionView可以显示一个页眉和页脚,与列表中的项目一起滚动。页脚指定将显示在列表末尾的字符串、绑定或视图。它粘不住这一页的底部。 解决方案: <StackLayout Orientation="Vertical"> <Label x:Name="Header_label" Text="Hader"
谢谢,CollectionView可以显示一个页眉和页脚,与列表中的项目一起滚动。页脚指定将显示在列表末尾的字符串、绑定或视图。它粘不住这一页的底部。 解决方案:
<StackLayout Orientation="Vertical">
<Label x:Name="Header_label" Text="Hader" VerticalOptions="StartAndExpand" BackgroundColor="Red"></Label>
<CollectionView ItemsSource="{Binding models}" ItemsLayout="VerticalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label x:Name="ID_label" Text="{Binding id}"></Label>
<Label x:Name="Name_label" Text="{Binding name}"></Label>
<Image x:Name="image" Source="{Binding image}"></Image>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Label x:Name="Footer_label" Text="Footer" VerticalOptions="EndAndExpand" BackgroundColor="Green"></Label>
</StackLayout>
public class model
{
public string name { get; set; }
public string image { get; set; }
public int id { get; set; }
}
一种简单的方法是创建带有标签的自定义控件,以模拟collectionview页眉和页脚
MyCustomControl:
<StackLayout Orientation="Vertical">
<Label x:Name="Header_label" Text="Hader" VerticalOptions="StartAndExpand" BackgroundColor="Red"></Label>
<CollectionView ItemsSource="{Binding models}" ItemsLayout="VerticalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label x:Name="ID_label" Text="{Binding id}"></Label>
<Label x:Name="Name_label" Text="{Binding name}"></Label>
<Image x:Name="image" Source="{Binding image}"></Image>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Label x:Name="Footer_label" Text="Footer" VerticalOptions="EndAndExpand" BackgroundColor="Green"></Label>
</StackLayout>
public class model
{
public string name { get; set; }
public string image { get; set; }
public int id { get; set; }
}
在自定义控件中绑定内容,也可以在主页中绑定
请注意:
在MainActivity.cs中初始化Xamarin.Forms之前,请添加以下标志
Forms.SetFlags("CollectionView_Experimental");
我已经上传到GitHub,您可以从Collectionview/MyCustomControl文件夹下载以供参考。
更新:
<StackLayout Orientation="Vertical">
<Label x:Name="Header_label" Text="Hader" VerticalOptions="StartAndExpand" BackgroundColor="Red"></Label>
<CollectionView ItemsSource="{Binding models}" ItemsLayout="VerticalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label x:Name="ID_label" Text="{Binding id}"></Label>
<Label x:Name="Name_label" Text="{Binding name}"></Label>
<Image x:Name="image" Source="{Binding image}"></Image>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<Label x:Name="Footer_label" Text="Footer" VerticalOptions="EndAndExpand" BackgroundColor="Green"></Label>
</StackLayout>
public class model
{
public string name { get; set; }
public string image { get; set; }
public int id { get; set; }
}
或者,您可以根据collectionview项的计数控制页脚
装箱自定义控件时,请使用IsVisible
属性
<Label x:Name="Footer_label" IsVisible="{Binding IsVisible}" Text="Footer" VerticalOptions="EndAndExpand" BackgroundColor="Green"></Label>
根据计数设置IsVisible
if (models.Count <8)
{
IsVisible = false;
}
else
{
IsVisible = true;
}
if(models.Count Zang谢谢你的详细回答。你真正想说的是,当你有1个或2个项目时,开箱即用的集合页脚永远不会粘在页面底部。我想开箱即用,但我不能。我必须使用stacklayout和endexpand。对吗?是的,collect的原始页脚ionview不会停留在页面底部。简单的方法是使用自定义控件,如我回复中的示例。