Пример #1
0
        /// <inheritdoc />
        public Task <DateTime?> DisplayDatePickerAsync(
            string title         = null,
            string message       = null,
            string actionButton  = null,
            string cancelButton  = null,
            DateTime?initialDate = null,
            DateTime?minDate     = null,
            DateTime?maxDate     = null)
        {
            var tcs = new TaskCompletionSource <DateTime?>();

            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;
                while (vc.PresentedViewController != null)
                {
                    vc = vc.PresentedViewController;
                }

                var datePickerView = new DatePickerView(vc.View.Bounds, title, message, actionButton, cancelButton, initialDate, minDate, maxDate);

                datePickerView.DateSelected += (obj) =>
                {
                    tcs.TrySetResult(obj);
                    datePickerView.Hide();
                };

                datePickerView.CancelRequested += () =>
                {
                    tcs.TrySetResult(null);
                    datePickerView.Hide();
                };

                datePickerView.Show(vc.View);
            });

            return(tcs.Task);
        }