using System; using System.Globalization; using Syncfusion.XForms.PopupLayout; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms.Resources.Typography; namespace InABox.Mobile { public class TimeButtonChangedArgs : EventArgs { public TimeSpan Time { get; private set; } public TimeButtonChangedArgs(TimeSpan time) { Time = time; } } public delegate void TimeButtonChanged(object sender, TimeButtonChangedArgs args); public class TimeSpanFormatter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if ((value is TimeSpan time) && (time != TimeSpan.Zero)) return $"{DateTime.Today.Add(time):hh\\:mm tt}"; return "--"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } [XamlCompilation(XamlCompilationOptions.Compile)] public partial class MobileTimeButton { private SfPopupLayout popup; public event TimeButtonChanged Changed; public static readonly BindableProperty TimeProperty = BindableProperty.Create( nameof(Time), typeof(TimeSpan), typeof(MobileTimeButton)); public TimeSpan Time { get => (TimeSpan)GetValue(TimeProperty); set => SetValue(TimeProperty,value); } public static readonly BindableProperty TextColorProperty = BindableProperty.Create( nameof(TextColor), typeof(Color), typeof(MobileTimeButton), XF.Material.Forms.Material.Color.OnSecondary); public Color TextColor { get => (Color)GetValue(TextColorProperty); set => SetValue(TextColorProperty, value); } public static readonly BindableProperty TypeScaleProperty = BindableProperty.Create( nameof(TypeScale), typeof(MaterialTypeScale), typeof(MobileTimeButton), MaterialTypeScale.Button); public MaterialTypeScale TypeScale { get => (MaterialTypeScale)GetValue(TypeScaleProperty); set => SetValue(TypeScaleProperty, value); } public static readonly BindableProperty ButtonColorProperty = BindableProperty.Create( nameof(ButtonColor), typeof(Color), typeof(MobileTimeButton), XF.Material.Forms.Material.Color.Secondary); public Color ButtonColor { get => (Color)GetValue(ButtonColorProperty); set => SetValue(ButtonColorProperty, value); } public static readonly BindableProperty BorderColorProperty = BindableProperty.Create( nameof(BorderColor), typeof(Color), typeof(MobileTimeButton), XF.Material.Forms.Material.Color.SecondaryVariant); public Color BorderColor { get => (Color)GetValue(BorderColorProperty); set => SetValue(BorderColorProperty, value); } // public static readonly BindableProperty PaddingProperty = BindableProperty.Create( // nameof(Padding), // typeof(Thickness), // typeof(TimeButton), // new Thickness(5)); // // public new Thickness Padding // { // get => (Thickness)GetValue(PaddingProperty); // set => SetValue(PaddingProperty, value); // } public MobileTimeButton() { InitializeComponent(); popup = new SfPopupLayout(); } private void _frame_OnClicked(object sender, EventArgs e) { popup.PopupView.WidthRequest = 300; popup.PopupView.HeightRequest = 500; popup.PopupView.ShowHeader = false; popup.PopupView.ShowFooter = false; MobileTimeSelector popupContent = new MobileTimeSelector(); popupContent.Time = Time; popupContent.TimeChanged += (o, args) => { Time = args.Time; Changed?.Invoke(this,new TimeButtonChangedArgs(Time)); }; popupContent.Margin = new Thickness(10); popupContent.HorizontalOptions = LayoutOptions.Fill; popupContent.VerticalOptions = LayoutOptions.Fill; popup.PopupView.ContentTemplate = new DataTemplate(() => popupContent); popup.Show(); } } }