Xamarin Forms:如何在2019年实现图像轮播

时间:2019-06-03 20:59:20

标签: android ios visual-studio xamarin.forms

有人能在2019年成功实现图片滑块吗?我发现的所有解决方案似乎都引用了一些不再可用的Nuget软件包。基本上,我想在ContentPage中添加一个部分,其中背景图像将连续变化(可能以定时方式)。

1 个答案:

答案 0 :(得分:0)

您需要基于水平ScrollView创建自己的控件。例如,像这样创建ContentView(使用xaml):

let gc:CGContext = CGContext.init(data: CVPixelBufferGetBaseAddress(destination), width: width, height: height, bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(destination), space: backImage.colorSpace!, bitmapInfo: backImage.bitmapInfo.rawValue)!;

   //TODO: Color getting inverted
gc.setFillColor(UIColor.red.cgColor);
gc.fill(frame);

在xaml中:

public partial class View1 : ContentView
{
    public static readonly BindableProperty CollectionProperty = BindableProperty.Create(nameof(Collection), typeof(List<ProxyObject>),
        typeof(View1), default(List<ProxyObject>), BindingMode.OneWay, propertyChanged: OnCollectionPropertyChanged);

    private static void OnCollectionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        if (!(bindable is View1 view1))
        {
            return;
        }
        foreach (var item in newValue as List<ProxyObject>)
        {
            view1.stackLayout.Children.Add(new Label());
        }
    }

    public List<ProxyObject> Collection
    {
        get { return (List<ProxyObject>)GetValue(CollectionProperty); }
        set { SetValue(CollectionProperty, value); }
    }

    public View1()
    {
        InitializeComponent();
    }
}

这是供参考的示例。