Hello,
Welcome to our Microsoft Q&A platform!
I follow you steps, But I do not meet this issue.
I can run it normally like following screenshot.
I add my code to AboutPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ShellCarouselView.Views.AboutPage"
xmlns:vm="clr-namespace:ShellCarouselView.ViewModels"
Title="{Binding Title}">
<ContentPage.Resources>
<ResourceDictionary>
<Color x:Key="Accent">#96d1ff</Color>
</ResourceDictionary>
</ContentPage.Resources>
<CarouselView ItemsSource="{Binding ItemsView}">
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentView Content="{Binding Content}" />
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage>
Here is background code of AboutPage.xaml
public partial class AboutPage : ContentPage
{
AboutViewModel aboutViewModels;
public AboutPage()
{
InitializeComponent();
aboutViewModels = new AboutViewModel();
BindingContext = aboutViewModels;
}
public static int value = 1;
protected override void OnAppearing()
{
base.OnAppearing();
// aboutViewModels.Items.Add(new Item() { Text = "tesx"+ (value++) });
aboutViewModels.ItemsView.Add(new View1());
}
}
Here is my viewModel.
public class AboutViewModel : BaseViewModel
{
public ObservableCollection<Item> Items { get; }
public ObservableCollection<ContentView> ItemsView { get; }
public AboutViewModel()
{
Items = new ObservableCollection<Item>();
ItemsView = new ObservableCollection<ContentView>();
Title = "About";
OpenWebCommand = new Command(async () => await Browser.OpenAsync("https://aka.ms/xamarin-quickstart"));
}
public ICommand OpenWebCommand { get; }
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
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.