1iveowl / Plugin.SegmentedControl

MIT License
170 stars 29 forks source link

System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array. #37

Closed romitnurani closed 6 years ago

romitnurani commented 6 years ago

Getting this exception when trying to assign variable of type "IList" to "Children" property of SegmentedControl.

- XAML FIle `<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:SegmentControlTestApp" xmlns:control="clr-namespace:SegmentedControl.FormsPlugin.Abstractions;assembly=SegmentedControl.FormsPlugin.Abstractions" x:Class="SegmentControlTestApp.MainPage">

<ContentPage.BindingContext>
    <local:ViewModel/>
</ContentPage.BindingContext>

<StackLayout>
    <control:SegmentedControl x:Name="oSegmentedControl" 
                        TintColor="BlueViolet"
                        SelectedTextColor="White"
                        DisabledColor="Gray"
                        Margin="8,8,8,8"
                        Children="{Binding ChildrenSegments}">
    </control:SegmentedControl>

</StackLayout>

`

- VIEWMODEL File ` public class ViewModel {

    public IList<SegmentedControlOption> ChildrenSegments = new List<SegmentedControlOption>()
        ;

    public ViewModel()
    {

        SegmentedControlOption oSegmentedControlOption1 = new SegmentedControlOption();
        oSegmentedControlOption1.Text = "Segment 1";

        SegmentedControlOption oSegmentedControlOption2 = new SegmentedControlOption();
        oSegmentedControlOption2.Text = "Segment 2";

        ChildrenSegments[0]=oSegmentedControlOption1;
        ChildrenSegments[1]=oSegmentedControlOption2;

    }
}`
rjantz3 commented 6 years ago

Is there a particular reason you're creating parts of the view in the view model?

Are you needing the ability to create the segments at runtime rather than in xaml?

romitnurani commented 6 years ago

Yes, My segments are decided and added on runtime. They aren't static/constant. It could be any number.

rjantz3 commented 6 years ago

Is it a one time binding or do you need the ability to update and remove segments anytime?

romitnurani commented 6 years ago

One time binding.

1iveowl commented 6 years ago

This seems to be related to #13

This is not currently a feature that is available. I'll consider it going forward. Also feel free to do a PR on this.

bluekuen commented 6 years ago

I also really need this feature. :)