最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Picker in Xamarin.Forms crashes on click - Stack Overflow

programmeradmin0浏览0评论

I'm developing a Xamarin.Forms app, and I'm facing an issue where the Picker crashes immediately when clicked. This problem occurs on Samsung and Google Pixel devices, but it does not happen on Huawei devices. The Picker doesn't open at all, and I get the following error message:

Invalid cast from 'System.String' to 'XXXXXXXXXXXXX.DataModel.Entities.Sorte'

The data for the Picker comes from a SQLite database, which I am not allowed to modify. I know that the first entry in the Picker is intentionally empty, and it is required by design.

Here are the relevant code snippets: VM

public Sorte SelectedSorte
{
    get
    {
        return SelectedOrderItem?.SelectedTaxItem?.SelectedSorte;
    }
    set
    {
        if (value != null && SelectedOrderItem?.SelectedTaxItem != null && value != SelectedOrderItem?.SelectedTaxtem?.SelectedSorte)
        {
            SelectedOrderItem.SelectedTaxItem.SelectedSorte = value;
            RaisePropertyChanged();
            Validate();
        }
    }
}

Here View I have tried using TargetNullValue='' and FallbackValue='' in XAML for the SelectedItem binding and ItemDisplayBinding binding, but unfortunately, it did not solve the issue.

<StackLayout
    x:Name="Sorte"
    Margin="0,10,0,0"
    Spacing="5">
    
    <Frame
        Padding="0"
        BorderColor="Transparent"
        CornerRadius="7">
        
        <Picker 
            x:Name="pickerSelectedSorte"
            ItemDisplayBinding="{Binding Description}"
            ItemsSource="{Binding SelectedOrderItem.SelectedTaxItem.OcSorten}"
            SelectedItem="{Binding SelectedSorte, Mode=TwoWay}" />
        
    </Frame>
</StackLayout>
发布评论

评论列表(0)

  1. 暂无评论