Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Picker not updating SelectedIndex (MVVM)

$
0
0

My picker SelectedItem is binding to SelectedProfile but I want the default value to be the index of the SelectedProfile, which is set in the ViewModel.

XAML:

                <Picker
                        Title="Select a profile"
                        TitleColor="Red"
                        ItemsSource="{Binding Profiles}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding SelectedProfile}" SelectedIndex="0">
                    <Picker.Behaviors>
                        <behaviors:EventToCommandBehavior EventName="SelectedIndexChanged" Command="{Binding PickerItemChangedCommand}" />
                    </Picker.Behaviors>
                </Picker>

In the ViewModel Constructor:

        SelectedProfile = DefaultProfile;

(DefaultProfile just has a Name property for now)

How can I get the the Picker to select the profile of SelectedProfile by default. Whenever the picker selection changes it correctly updates the SelectedProfile as I have implemented.

EDIT:
SelectedIndex is working through binding and setting up the prop on the VM... but if I set it to 0 the 1st element never shows up, it only works on index 1 and above, missing the first one out.


Viewing all articles
Browse latest Browse all 89864

Trending Articles