Swipegesture仅在xamarin格式的标题中
我需要一个视图,其中将有一个标题和内容。 假设应用程序显示水果名称及其详细信息 假设第一个视图的标题是“草莓”,内容是草莓的图片和细节。我只需要在标题“草莓”上进行滑动操作,这样在滑动它时,下一个项目“芒果”将在标题中出现,下面是芒果的详细信息 所以现在标题“Mango”必须可以左右滑动。向右滑动可查看上一个水果草莓的详细信息,向左滑动可查看下一个水果橙的详细信息 如果橙色是最后一个水果,它应该在它的标题中有滑动动作,仅用于查看上一个图像,因为它没有任何东西显示为下一个项目Swipegesture仅在xamarin格式的标题中,xamarin,xamarin.forms,swipe,Xamarin,Xamarin.forms,Swipe,我需要一个视图,其中将有一个标题和内容。 假设应用程序显示水果名称及其详细信息 假设第一个视图的标题是“草莓”,内容是草莓的图片和细节。我只需要在标题“草莓”上进行滑动操作,这样在滑动它时,下一个项目“芒果”将在标题中出现,下面是芒果的详细信息 所以现在标题“Mango”必须可以左右滑动。向右滑动可查看上一个水果草莓的详细信息,向左滑动可查看下一个水果橙的详细信息 如果橙色是最后一个水果,它应该在它的标题中有滑动动作,仅用于查看上一个图像,因为它没有任何东西显示为下一个项目 我把所有水果的名字和
我把所有水果的名字和其他细节都列在清单上了。请告诉我如何实现这一点。Xamarin.Forms提供了滑动手势,您可以将滑动手势应用于标题
最简单的方法是使用a作为标题 下面是一个简单的示例: xaml页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NewForms.CollectionViewPage">
<ContentPage.Content>
<StackLayout>
<CarouselView x:Name="collection" ItemSource={Binding Fruits} HeightRequest="50" Loop="False">
<CarouselView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}"></Label> //this for the header content
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<StackLayout Orientation="Vertical" BindingContext="{Binding Path=CurrentItem,Source={x:Reference collection}}">
<Label Text="{Binding Details}"></Label> //binding the details content
</StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
viewmodel:
class FruitModel
{
public ObservableCollection<Fruit> Fruits { get; set; }
public FruitModel()
{
Fruits = new ObservableCollection<Fruit>();
Fruits.Add(new Fruit() { Name = "Apple", Details = "Thi is an apple" });
Fruits.Add(new Fruit() { Name = "Pear", Details = "Thi is a Pear" });
Fruits.Add(new Fruit() { Name = "Banana", Details = "Thi is a Banana" });
Fruits.Add(new Fruit() { Name = "Strawberry", Details = "Thi is a Strawberry" });
}
}
您可以根据需要更改模板和数据库。但我只需要在标题中而不是在整个视图中执行滑动操作:(将尝试此操作并进行更新。谢谢@leocold it work?是的,它可以工作。谢谢@Leo您可以编辑它以为旋转视图添加ItemSource={Binding Fruits}吗?好的,我将编辑它。
class FruitModel
{
public ObservableCollection<Fruit> Fruits { get; set; }
public FruitModel()
{
Fruits = new ObservableCollection<Fruit>();
Fruits.Add(new Fruit() { Name = "Apple", Details = "Thi is an apple" });
Fruits.Add(new Fruit() { Name = "Pear", Details = "Thi is a Pear" });
Fruits.Add(new Fruit() { Name = "Banana", Details = "Thi is a Banana" });
Fruits.Add(new Fruit() { Name = "Strawberry", Details = "Thi is a Strawberry" });
}
}
class Fruit
{
public string Name { get; set; }
public string Details { get; set; }
}