Xamarin.forms: Picker control's ItemsSource property does not support full TwoWay binding

Created on 14 Oct 2018  Â·  4Comments  Â·  Source: xamarin/Xamarin.Forms

Description

When using a Picker control with its ItemsSource bound to an ObservableCollection, the Picker only responds to additions and deletions in the collection, not to updates in the collection's members.

Steps to Reproduce

  1. Create a Picker control bound to an ObservableCollection
  2. Mutate the displayed property (that is, the property denoted by the Picker's ItemDisplayBinding) of one member of the collection

Expected Behavior

The new value should appear in the Picker.

Actual Behavior

No changes are shown in the Picker.

Basic Information

  • Version with issue: 3.1.0.697729
  • Last known good version: none
  • IDE: Visual Studio 2017
  • Platform Target Frameworks:

    • Android: 8.1 - API 27

  • Nuget Packages: Refactored.MvvmHelpers (although the problem presents without this package as well)

More Information

As a response on StackOverflow indicated, the Picker source code includes a call to UnApply() in GetDisplayMember(). This would seem to indicate that this behavior might be by design -- but if so, it's:

  • incomplete -- since ObservableCollection.Add() and .Remove() work as expected
  • undocumented -- the docs page for Picker does not indicate that ItemsSource is intended to only work OneWay.
  • unnecessary -- why make Picker the only obligate OneWay control?

Screenshots

Before: https://github.com/grahampcharles/PickerUpdateSample/blob/master/PickerUpdateSample/PickerUpdateSample/Screenshots/Screenshot%20Before.png

After: https://github.com/grahampcharles/PickerUpdateSample/blob/master/PickerUpdateSample/PickerUpdateSample/Screenshots/Screenshot%20xAfter.png

Reproduction Link

Here's a sample: https://github.com/grahampcharles/PickerUpdateSample

5 proposal-open enhancement âž•

Most helpful comment

To clarify, what you are expecting is that if the Picker is using the ItemDisplayBinding property, when that property changes on the underlying item the update display value should be reflected in the Picker.

That's not currently supported, but it would be nice. I'm adding it to our enhancements list.

This issue title is misleading; this doesn't have anything to do with two-way binding, it's just that the Picker does not monitor individual item property changes.

All 4 comments

To clarify, what you are expecting is that if the Picker is using the ItemDisplayBinding property, when that property changes on the underlying item the update display value should be reflected in the Picker.

That's not currently supported, but it would be nice. I'm adding it to our enhancements list.

This issue title is misleading; this doesn't have anything to do with two-way binding, it's just that the Picker does not monitor individual item property changes.

Looking forward to this being fixed, and waiting patiently. Is there any chance this will be on an upcoming sprint sometime soon?

What's the current status of this issue?
Or could you provide us with the workaround?

Btw, issue title is misleading, it has nothing to do with ItemsSource. Can someone change it?
Thanks.

Just a heads up, the referenced source code for this defect does reference ItemsSource as per the MainPage.xaml file.

<Picker x:Name="thePicker" ItemsSource="{Binding MyItems}" ItemDisplayBinding="{Binding MyItemName}"></Picker>
Was this page helpful?
0 / 5 - 0 ratings