Hello,
From this line of the code: ItemsSource="{Binding Source={x:Reference CarView}, Path=ItemsSource, Mode=OneWay}"
, I know you want to set a BindableProperty
and pass the ItemsSource
. I‘m not sure what type of ItemsSource
, so I set List<String>
for testing. Please refer to the following code:
public partial class Carousel: ContentView
{
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create("ItemsSource", typeof(List<String>), typeof(Carousel), new List<String>());
public List<String> ItemsSource
{
get { return (List<String>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public Carousel()
{
InitializeComponent();
}
}
Consume the custom Carousel control: XMAL(adding Carousel in MainPage)
<local:Carousel ItemsSource="{Binding DataSource}"></local:Carousel>
Setting BindingContext for testing
public List<string> DataSource { get; set; }
public MainPage()
{
InitializeComponent();
DataSource = new List<string>()
{
"dotnet_bot.png",
"https://aka.ms/campus.jpg",
"dotnet_bot.png",
"https://aka.ms/campus.jpg"
};
this.BindingContext = this;
}
Best Regards, Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.