程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了滑动手势仅在 xamarin 形式的标题中大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决滑动手势仅在 xamarin 形式的标题中?

开发过程中遇到滑动手势仅在 xamarin 形式的标题中的问题如何解决?下面主要结合日常开发的经验,给出你关于滑动手势仅在 xamarin 形式的标题中的解决方法建议,希望对你解决滑动手势仅在 xamarin 形式的标题中有所启发或帮助;

我需要一个包含标题和内容的视图。 假设应用显示水果名称及其详细信息。

假设第一个视图将具有标题 -“草莓”,内容将是草莓的图片和详细信息。我只需要在标题“草莓”上执行滑动操作,以便在滑动它时,下一个项目“芒果”出现在标题中,下面是芒果的详细信息。

所以现在标题“Mango”必须可以左右滑动。向右滑动查看上一个水果草莓的详细信息或向左滑动查看下一个水果-橙子的详细信息。

如果橙色是最后一个水果,它应该在它的标题中有滑动操作,只能查看上一个图像,因为它没有任何显示为下一个项目。

我有一个列表中的所有水果名称和其他详细信息。请告诉我如何实现这一目标

解决方法

@H_944_14@

最简单的方法是使用 CarouselView 作为标题。

一个简单的例子,如下所示:

页面 xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/scheR_839_11845@as/2014/forms"
         xmlns:x="http://scheR_839_11845@as.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>

page.xaml.cs:

  public CarouselViewPage()
    {
        InitializeComponent();
        FruitModel fruitModel = new FruitModel();
        BindingContext = fruitModel;
    }

视图模型:

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; }
 }

您可以根据需要更改模板和数据库。

,

Xamarin.Forms 提供滑动手势,您可以将滑动手势应用于标题。

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/swipe

大佬总结

以上是大佬教程为你收集整理的滑动手势仅在 xamarin 形式的标题中全部内容,希望文章能够帮你解决滑动手势仅在 xamarin 形式的标题中所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:xamarin