3
votes

I am working on Xamarin.Forms I got error

"System.InvalidCastException: Specified cast is not valid."

I found one similar problem in StackOverflow Xamarin.Forms Binding Specified cast is not valid

but here answered as remove grid but in my case, I am not using grid why I am getting error

<StackLayout x:Name="roll"  HeightRequest="0"> 

        <SearchBar Placeholder="Type to Search" TextChanged="SearchDropDown" />

        <ListView  x:Name="SearchDropDownList" ItemsSource="{Binding Items}" CachingStrategy="RecycleElement" ItemSelected="OnItemSelected">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <input:CheckBox Text="{Binding Text}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

</StackLayout>

I am using Xamarin.Forms.InputKit package from NuGet Package Manager.

How do I resolve this?

1

1 Answers

2
votes

I resolved the error by changing the code into following

<ListView  x:Name="SearchDropDownList" ItemsSource="{Binding Items}" CachingStrategy="RecycleElement" ItemSelected="OnItemSelected">
                        <ListView.ItemTemplate>
                            <DataTemplate>                                   
                                <ViewCell>
                                    <ViewCell.View>
                                        <StackLayout>
                                            <input:CheckBox Text="{Binding Text}" Type="Check"/>
                                        </StackLayout>
                                    </ViewCell.View>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>