【问题标题】:System.InvalidCastException: Specified cast is not valid in xamarin forms?System.InvalidCastException:指定的强制转换在 xamarin 表单中无效?
【发布时间】:2019-05-18 09:21:21
【问题描述】:

我正在使用 Xamarin.Forms 我收到错误

“System.InvalidCastException:指定的强制转换无效。”

我在 StackOverflow Xamarin.Forms Binding Specified cast is not valid 中发现了一个类似的问题

但这里回答为删除网格,但在我的情况下,我没有使用网格,为什么会出错

<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>

我正在使用 NuGet 包管理器中的 Xamarin.Forms.InputKit 包。

我该如何解决这个问题?

【问题讨论】:

标签: xamarin xamarin.forms xamarin.android


【解决方案1】:

我通过将代码更改为以下解决了错误

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2022-01-13
    • 1970-01-01
    相关资源
    最近更新 更多