Search code examples
xamarinmvvmdata-binding

Xamarin Picker inside ListView ItemDisplayBinding Binding: Property not found


I've a Picker inside a ListView with databinding:

          <ListView 
            ItemsSource="{Binding CursorPrintParametersList}">
            <ListView.ItemTemplate>
              <DataTemplate x:DataType="models:CursorPrintParameters">
                <ViewCell>
                    <Grid>
                      <Picker 
                        ItemsSource="{Binding LabelTypes}"
                        SelectedItem="{Binding SelectedLabelType}"
                        ItemDisplayBinding="{Binding Description}"
                        />

                    </Grid>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>

where CursorPrintParametersList is

ObservableCollection<CursorPrintParameters> CursorPrintParametersList

and

public class CursorPrintParameters : INotifyPropertyChanged
{


    public event PropertyChangedEventHandler PropertyChanged;


    public List<BaseDto> LabelTypes { get; set; }


    private BaseDto selectedLabelType;
    public BaseDto SelectedLabelType
    {
        get => selectedLabelType;
        set
        {
            if (value == null) return;

            selectedLabelType = value;
            RaisePropertyChanged(nameof(SelectedLabelType));
        }
    }



}


public class BaseDto
{
    public string Code{ get; set; }
    public string Description{ get; set; }
}

I'm unable to set the ItemDisplayBinding="{Binding Description}" for the Picker, getting a

Property 'Description' not found on 'CursorPrintParameters'     

If i put the picker outside the ListView, everything works fine. Any help? Thanks


Solution

  • i reproduce your issue in Xamarin.Forms version 3.6.0.34457

    and the solution is delete below codes in DataTemplate :

    x:DataType="models:CursorPrintParameters" 
    

    It is better to upgrade to the latest version if possible, as there may be some API changes