0
votes

My issue is that I have 2 picker controls. 1 of these picker controls is bound to list a and one of these picker controls is bound to list b. Both of these controls display the data I need them to with the correct display bindings working fine.

My problem is when I bind the selectedItem property, it works for list a but doesn't for list b. I've checked that the code is literally a like for like copy of each other.

I have been using the syncfusion Combobox but switched to the picker as I thought there was an issue here but there isn't. Whatever is happening is totally down to whatever I'm doing.

The usage scenario is that I bring down a list of payment types from my API and populate a picker based on this. This works.

The datasource for my main view contains an ID. When I am modifying a record, I run a method called update to find the selectedItem. I'm not happy with this approach and would be interested to see what other people use.

The update method gets the datasources for the pickers and finds what I would expect to be the selected item. This works fine also but doesn't bind.

 [Serializable]
    public class PaymentInformation :BaseModel 
    {

        public int? ID { get; set; }

        public DateTime? StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int? PaymentTypeId { get; set; }

        public string PaymentTo { get; set; }

        public string Location { get; set; }

        public string Notes { get; set; }

        public PersonInformation PersonBudget { get; set; }

        public decimal AmountPaid { get; set; }

        public decimal AmountReceived { get; set; }

        public double TotalHours { get; set; }

        public void Update(ObservableCollection<ResourceInformation> resources , ObservableCollection<PaymentTypeInformation> paymentTypes)
        {
           if(PaymentTypeId != null) this.PaymentTypeInformation1 = paymentTypes?.FirstOrDefault((paymentType) => paymentType.ID == PaymentTypeId.Value);
            this.Resource = resources?.FirstOrDefault((resource) => resource.ResourceId == PersonBudget?.ID);
        }

        private PaymentTypeInformation _paymentTypeInformation;

        private PaymentTypeInformation PaymentTypeInformation1 { get { return _paymentTypeInformation; } set { _paymentTypeInformation = value; OnPropertyChanged(nameof(PaymentTypeInformation1)); } }

        private ResourceInformation _resource;

        public ResourceInformation Resource { get { return _resource; } set { _resource = value; OnPropertyChanged(nameof(Resource)); } }

    }

The underlying xaml is:

 <Label Grid.Row="8" Grid.Column="0" Text="Payment Type:" />
            <Picker BackgroundColor="White" Grid.Row="8" Grid.Column="1" ItemsSource="{Binding PaymentTypesDataSource}"  ItemDisplayBinding="{Binding Path=DisplayText}" IsEnabled="{Binding IsProcessing, Converter={StaticResource reverseBoolConvertor}}" SelectedItem="{Binding DataSource.PaymentTypeInformation1, Mode=TwoWay}" />

The expected result is that the drop down initializes with the selectedItem which it doesn't (in one usage scenario - the other one works fine).

1
Your question is about binding but you don't show your actual bindings, and the code you did post doesn't really include enough context to demonstrate the problem you're having. - Jason
Agreed, post updated with actual code sample. - Chris Boot

1 Answers

0
votes

Couldn't see the wood for the trees.

private PaymentTypeInformation PaymentTypeInformation1
{ 
    get
    {
        return _paymentTypeInformation;
    }
    set
    { 
        _paymentTypeInformation = value;
        OnPropertyChanged(nameof(PaymentTypeInformation1));
    } 
}

Can't bind to a private property - changed to public and immediately work. Stuck on this for a day as bonkers as that is to believe.