Keep getting Default value didnt match return type error

goldami1goldami1 Member ✭✭
edited April 2018 in Xamarin.Forms

Hi,

I try to use CarouselViewControl from @alexrainman while implementing a MVVM pattern.
Although everything seems ok, I keep getting this error "Default value did not match return type. Parameter name: defaultValue (ArgumentException)".

My Model:

public class TabbedPageIconModel
{
        public Xamarin.Forms.Image MyImage { get; set; }
        public string MyImageURL { get; set; }
        public string IconName { get; set; }
}

My ViewModel:

public class FilterViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public Command MyCommand { get; protected set; }
    private ObservableCollection<TabbedPageIconModel> _myItemsSource;
    public ObservableCollection<TabbedPageIconModel> MyItemsSource
    {
        get
        {
            return _myItemsSource;
        }
        set
        {
            _myItemsSource = value;
            OnPropertyChanged(nameof(MyItemsSource));
        }
    }

    public FilterViewModel()
    {
        MyItemsSource = new ObservableCollection<TabbedPageIconModel>()
        {
            new TabbedPageIconModel() { MyImageURL = "picsum.photos/201", MyImage = new Image(){Source = "picsum.photos/201" }, IconName="Banana1" },
            new TabbedPageIconModel() { MyImageURL = "picsum.photos/202", MyImage = new Image(){Source = "picsum.photos/202" }, IconName="Banana2" },
            new TabbedPageIconModel() { MyImageURL = "picsum.photos/203", MyImage = new Image(){Source = "picsum.photos/203" }, IconName="Banana3" }
        };

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

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

My View:

<ContentPage.BindingContext>
    <ViewModels:FilterViewModel/>
</ContentPage.BindingContext>

<control:CarouselViewControl 
    ItemsSource="{Binding MyItemsSource}" ShowArrows="True" ShowIndicators="True" Orientation="Horizontal">
    <control:CarouselViewControl.ItemTemplate>
        <DataTemplate>
            <ContentPage>
                <StackLayout>
                    <Image Source="{Binding MyImageURL}"/>
                </StackLayout>
            </ContentPage>
        </DataTemplate>
    </control:CarouselViewControl.ItemTemplate>
</control:CarouselViewControl>

Answers

Sign In or Register to comment.