No need to manually handle the SelectedIndex
. You can use the Picker
's SelectedItem
property. Just make sure your types are the same. For example, if your ItemsSource
is bound to a property:
BookTitles List<string> { get; set; }
your SelectedItem
has to be something like:
SelectedBookTitle string { get; set; }
Make sure to set the SelectedBookTitle
value to show a title when the page is first shown.
Do not forget to set Mode
to TwoWay
on the SelectedItem Binding
.
for example:
<Picker ItemsSource="{Binding BookTitles}" SelectedItem="{Binding
SelectedBookTitle, Mode=TwoWay}" />
This will ensure the title is shown when the page is first displayed,
and keeps the value of SelectedBookTitle
equal on the Page and codebehind/viewmodel.
No need to use behaviours in this example.
SelectedItem
is same as that of the type used inItemsSource
collection. – Sharada Gururaj