using System; using System.Globalization; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; namespace ZB.MOM.WW.OtOpcUa.Client.UI.Controls; /// /// A date/time range picker using formatted text boxes and preset duration buttons. /// Text properties are two-way bound to TextBoxes via XAML; DateTime properties /// are synced in code-behind. /// public partial class DateTimeRangePicker : UserControl { private const string Format = "yyyy-MM-dd HH:mm:ss"; public static readonly StyledProperty StartDateTimeProperty = AvaloniaProperty.Register( nameof(StartDateTime), defaultBindingMode: Avalonia.Data.BindingMode.TwoWay); public static readonly StyledProperty EndDateTimeProperty = AvaloniaProperty.Register( nameof(EndDateTime), defaultBindingMode: Avalonia.Data.BindingMode.TwoWay); public static readonly StyledProperty StartTextProperty = AvaloniaProperty.Register(nameof(StartText), defaultValue: ""); public static readonly StyledProperty EndTextProperty = AvaloniaProperty.Register(nameof(EndText), defaultValue: ""); public static readonly StyledProperty MinDateTimeProperty = AvaloniaProperty.Register(nameof(MinDateTime)); public static readonly StyledProperty MaxDateTimeProperty = AvaloniaProperty.Register(nameof(MaxDateTime)); private bool _isUpdating; public DateTimeRangePicker() { InitializeComponent(); } public DateTimeOffset? StartDateTime { get => GetValue(StartDateTimeProperty); set => SetValue(StartDateTimeProperty, value); } public DateTimeOffset? EndDateTime { get => GetValue(EndDateTimeProperty); set => SetValue(EndDateTimeProperty, value); } public string StartText { get => GetValue(StartTextProperty); set => SetValue(StartTextProperty, value); } public string EndText { get => GetValue(EndTextProperty); set => SetValue(EndTextProperty, value); } public DateTimeOffset? MinDateTime { get => GetValue(MinDateTimeProperty); set => SetValue(MinDateTimeProperty, value); } public DateTimeOffset? MaxDateTime { get => GetValue(MaxDateTimeProperty); set => SetValue(MaxDateTimeProperty, value); } protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); var startInput = this.FindControl("StartInput"); var endInput = this.FindControl("EndInput"); if (startInput != null) startInput.LostFocus += OnStartLostFocus; if (endInput != null) endInput.LostFocus += OnEndLostFocus; var last5Min = this.FindControl