How to set initial value to Xamarin.Forms SfPicker
The Xamarin.Forms SfPicker provides a support to initially selected values by setting initial value to the SelectedItem property. You can customize the selected items of Xamarin.Forms SfPicker. The Xamarin.Forms SfPicker initially selected the first item in collection without setting any value to SelectedItem.
The following steps explain how to set initial value to Xamarin.Forms SfPicker.
Step 1: Create a view model class, and declare the properties that needs to be assigned.
Step 2: Add items to display the data in Xamarin.Forms SfPicker.
Step 3: Create a symbol ObservableCollection, and in which add items to set initial value in Xamarin.Forms SfPicker.
Step 4: Initialize the Xamarin.Forms SfPicker in XAML page with the properties need to be assigned.
Step 5 : Bind the initial value to SelectedItem property to display the initial value in Xamarin.Forms SfPicker.
XAML:
<sfPicker:SfPicker PickerHeight="400" PickerWidth="300" SelectedItem="{Binding StartValue}" ItemsSource="{Binding JobLists}" ColumnHeaderText="{Binding ColumnHeaders}" HeaderText="Pick a job" ShowColumnHeader="True" ShowHeader="True"> </sfPicker:SfPicker>
Output:
You can find the sample in the following link: Sample