Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

PickerBindBehavior

Mark Smith edited this page Aug 29, 2016 · 1 revision

PickerBindBehavior

The PickerBindBehavior behavior allows you to support a data-bound set of items for the Xamarin.Forms Picker control. This class allows the Picker to be easily populated and managed using MVVM. The default implementation does not provide bindable properties and requires a direct dependency on the Picker.

Properties

  • Items : the IEnumerable list of items to display in the Picker. The behavior will use ToString to turn each item into a valid text label to display.

  • SelectedItem : the object from the Items collection that is currently selected by the Picker.

Example

<Picker ...>
   <Picker.Behaviors>
      <inf:PickerBindBehavior Items="{Binding Colors}" 
                          SelectedItem="{Binding FavoriteColor}" />
   </Picker.Behaviors>
</Picker>

Here's the ViewModel which is set as the BindingContext for the picker:

class MyViewModel : SimpleViewModel
{
   public IList<Color> Colors { ... }
   public Color FavoriteColor { ... }
}