首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin表单:可以通过右翻转或左翻转查看图片吗?

Xamarin表单:可以通过右翻转或左翻转查看图片吗?
EN

Stack Overflow用户
提问于 2019-08-08 11:14:53
回答 3查看 1K关注 0票数 1

我的申请书里有一张照片库。如果我选择一张照片,所选的照片将显示在另一个页面上,并带有左右箭头。点击左边箭头时,相册的前一张图片在屏幕上是可见的,如果点击右箭头,相册中的下一张图片将出现在屏幕上。

截图

我需要查看下/先前的图片,而不点击箭头。可以通过左右滑动来查看图片吗?是否有任何控制来识别右/左屏幕滑动?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-08-08 11:22:56

CarouselView来找你了!!

https://devblogs.microsoft.com/xamarin/xamarin-forms-4-0-feature-preview-an-entirely-new-point-of-collectionview/

技术注意:在您在CollectionView和AppDelegate中初始化Xamarin.Forms之前,使用一个特性标志启用Xamarin.Forms(这也启用了MainActivity.cs ):

代码语言:javascript
复制
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");

如果不想使用新特性,可以添加SwipeGestureRecognizer

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

为了快速加载和缓存图像,我使用这个库

https://github.com/luberda-molinet/FFImageLoading

票数 3
EN

Stack Overflow用户

发布于 2019-08-08 16:01:39

但是要小心,因为CarouselView在预览中,您不应该在生产应用程序中使用它。

因此,在没有发布CollectionView之前,您可以使用这个:

https://github.com/roubachof/Sharpnado.Presentation.Forms#carousel-layout

票数 0
EN

Stack Overflow用户

发布于 2019-08-09 03:00:41

我需要查看下/先前的图片,而不点击箭头。可以通过左右滑动来查看图片吗?是否有任何控制来识别右/左屏幕滑动?

如果您想这样做,我建议您可以使用CarouselViewControl。您需要通过nuget安装CarouseView.FormsPlugin。你可以点击箭头,或者向右滑动来查看图片。

然后添加此引用

代码语言:javascript
复制
<ContentPage
x:Class="Demo1.listviewcontrol.Page3"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:cv="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions">
<ContentPage.Content>
    <Grid>
        <cv:CarouselViewControl
            x:Name="carousel"
            AnimateTransition="True"
            ItemsSource="{Binding MyItemsSource}"
            Orientation="Horizontal"
            PositionSelected="Handle_PositionSelected"
            PositionSelectedCommand="{Binding MyCommand}"
            Scrolled="Handle_Scrolled"
            ShowArrows="true"
            ShowIndicators="true" />
    </Grid>
</ContentPage.Content>

代码语言:javascript
复制
public partial class Page3 : ContentPage
{
    public Page3 ()
    {
        InitializeComponent ();
        this.BindingContext = new MainViewModel();
    }

    private void Handle_PositionSelected(object sender, CarouselView.FormsPlugin.Abstractions.PositionSelectedEventArgs e)
    {
        Debug.WriteLine("Position " + e.NewValue + " selected.");
    }

    private void Handle_Scrolled(object sender, CarouselView.FormsPlugin.Abstractions.ScrolledEventArgs e)
    {
        Debug.WriteLine("Scrolled to " + e.NewValue + " percent.");
        Debug.WriteLine("Direction = " + e.Direction);
    }
}

public class MainViewModel
{
   public ObservableCollection<View> _myItemsSource;
    public ObservableCollection<View> MyItemsSource
    {
        set
        {
            _myItemsSource = value;               
        }
        get
        {
            return _myItemsSource;
        }
    }

    public Command MyCommand { protected set; get; }
    public MainViewModel()
    {
        MyItemsSource = new ObservableCollection<View>()
        {
            new CachedImage() { Source = "a1.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill },
            new CachedImage() { Source = "c2.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill },
            new CachedImage() { Source = "c3.jpg", DownsampleToViewSize = true, Aspect = Aspect.AspectFill }
        };

        MyCommand = new Command(() =>
        {
            Debug.WriteLine("Position selected.");
        });
    }

}

我使用CacheImage,所以通过nuget安装Xamarin.FFimageLoading.Forms。

请在主活动OnCreate方法中添加以下代码

代码语言:javascript
复制
 CarouselViewRenderer.Init();
        CachedImageRenderer.Init(true);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57411292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档