Events in Xamarin TimePicker (SfTimePicker)

18 Jun 20213 minutes to read

Three events are used when the SfTimePicker is in Dialog mode.

  • Opened
  • Closing
  • Closed

Opened event

The Opened event occurs when the SfTimePicker is opened.

Closing event

The Closing event occurs when the SfTimePicker closes.

Drop-down close can be restricted by setting e.cancel to true.

Closed event

The Closed event was triggered, after the SfTimePicker was closed.

<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:timePicker="clr-namespace:Syncfusion.XForms.Pickers;assembly=Syncfusion.SfPicker.XForms"
                 x:Class="TimePickerSample.MainPage">
    
     ...
     <timePicker:SfTimePicker x:Name="timePicker"                                          PickerMode="Dialog"
                                 Opened="TimePicker_Opened" 
                                 Closing="TimePicker_Closing"
                                 Closed="TimePicker_Closed"
                                 >
        </timePicker:SfTimePicker>
    </ContentPage>
public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            timePicker.Opened += TimePicker_Opened;
            timePicker.Closing += TimePicker_Closing;
            timePicker.Closed += TimePicker_Closed;
        }

       
        private void TimePicker_Opened(object sender, EventArgs e)
        {
        }

        private void TimePicker_Closing(object sender, Syncfusion.XForms.Core.CancelEventArgs e)
        {
            //To restrict the timepicker get close, set e.Cancel to true.
            e.Cancel = true;
        }

        private void TimePicker_Closed(object sender, EventArgs e)
        {
        }
    }