How to set null value to items in Xamarin.Forms SfPicker
The Xamarin.Forms SfPicker provides a support to set null value to picker items. This can be achieved by setting SelectedItem property to null. The footer view of Xamarin.Forms SfPicker can be customized to any custom view such as image, button, and label. By setting any view to the FooterView property, you can customize the footer of Xamarin.Forms SfPicker. In this example, multiple buttons have been created and the buttons have been set to footer view. Using the events of buttons, SelectedItem is set to null.
The following steps explain how to set null value to items in picker and how to customize the footer view of Xamarin.Forms SfPicker.
Step 1: Create a simple class, which should be inherited from SfPicker to add the date picker in Xamarin.Forms SfPicker. For more details about adding date picker to Xamarin.Forms SfPicker, refer to the sample.
Step 2: Add that class in XAML page and set the properties that needs to be assigned.
Step 3: Add any custom view to the FooterView property in Xamarin.Forms SfPicker.
The following code sample demonstrates how to create multiple buttons in footer view and how to set null value to items in Xamarin.Forms SfPicker.
XAML:
<ContentPage.Content> <local:DateTimePicker x:Name="picker" ShowFooter="True" PickerHeight="400" PickerWidth="300" ColumnHeaderHeight="40"> <local:DateTimePicker.FooterView> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Button Grid.Row="0" Grid.Column="0" BackgroundColor="Green" Text="Clear" Clicked="Clear_Clicked"/> <Button Grid.Row="0" Grid.Column="1" BackgroundColor="Green" Text="Ok"/> <Button Grid.Row="0" Grid.Column="2" BackgroundColor="Green" Text="Cancel"/> </Grid> </local:DateTimePicker.FooterView> </local:DateTimePicker> </ContentPage.Content>
C#:
Following code snippet illustrates how to set null value to SelectedItem in Xamarin.Forms SfPicker.
private void Clear_Clicked(object sender, EventArgs e)
{
picker.SelectedItem = null;
}
Output:

You can download the sample from this following link: Sample