forked from xamarinhq/xamu-infrastructure
-
Notifications
You must be signed in to change notification settings - Fork 0
PickerBindBehavior
Mark Smith edited this page Aug 29, 2016
·
1 revision
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.
-
Items: theIEnumerablelist of items to display in thePicker. The behavior will useToStringto turn each item into a valid text label to display. -
SelectedItem: the object from theItemscollection that is currently selected by thePicker.
<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 { ... }
}