I've finally figured out how to get this working.
Here is the template class I had to make
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoomStick.Models;
using BoomStick.Services;
using Syncfusion.SfCarousel.XForms;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace BoomStick.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TemplateCarouselView : SfCarousel
{
public DataTemplate dt;
public TemplateCarouselView()
{
InitializeComponent();
dt = new DataTemplate(() =>
{
var keyLayout = new StackLayout();
var bindPhoto = new Binding()
{
Converter = new FillImageFromBytes(),
Path = "Image"
};
var bindTapped = new Binding()
{
Path = "OnTapped"
};
var bindLocalPath = new Binding()
{
Converter = new FillImageFromBytes(),
Path = "."
};
var tgRec = new TapGestureRecognizer()
{
CommandParameter = bindLocalPath,
NumberOfTapsRequired = 1
};
tgRec.Tapped += async (s, e) =>
{
var act = await Application.Current.MainPage.DisplayActionSheet(
StringTools.GetStringResource("szPhotoOptions"),
null,
StringTools.GetStringResource("szOK"),
ActionList.ToArray());
await TapHandler.ImageTapHandler((Photos)((TappedEventArgs)e).Parameter, act, KeyButton, ParentObject);
};
tgRec.SetBinding(TapGestureRecognizer.CommandProperty, bindTapped);
tgRec.SetBinding(TapGestureRecognizer.CommandParameterProperty, ".");
keyLayout.GestureRecognizers.Add(tgRec);
var img = new Image()
{
Aspect = Aspect.AspectFit,
HeightRequest = 350,
WidthRequest = 250,
};
img.SetBinding(Image.SourceProperty, bindPhoto);
var lblFileName = new Label()
{
HorizontalTextAlignment = TextAlignment.Center,
};
lblFileName.SetBinding(Label.TextProperty, "FileName");
keyLayout.Children.Add(img);
keyLayout.Children.Add(lblFileName);
return new ViewCell { View = keyLayout };
});
Carousel.ItemTemplate = dt;
}
public static readonly BindableProperty ActionListProperty = BindableProperty.Create(nameof(ActionList), typeof(List<string>), typeof(List<string>));
public List<string> ActionList
{
get
{
return (List<string>)GetValue(ParentObjectProperty);
}
set
{
SetValue(ParentObjectProperty, value);
}
}
public static readonly BindableProperty ParentObjectProperty = BindableProperty.Create(nameof(ParentObject), typeof(Object), typeof(Object));
public Object ParentObject
{
get
{
return (Object)GetValue(ParentObjectProperty);
}
set
{
SetValue(ParentObjectProperty, value);
}
}
public static readonly BindableProperty KeyButtonProperty = BindableProperty.Create(nameof(KeyButton), typeof(ImageButton), typeof(ImageButton));
public ImageButton KeyButton
{
get
{
return (ImageButton)GetValue(KeyButtonProperty);
}
set
{
SetValue(KeyButtonProperty, value);
}
}
}
}
I can then instantiate it like this
<core:TemplateCarouselView
x:Name="carousel"
ActionList="{Binding Path=ActionList}"
KeyButton="{x:Reference KeyImageButton}"
ParentObject="{Binding Path=MyClass}" />
It took some time, and I couldn't have done it without some help!
Cheers!