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: "");
private bool _isUpdating;
/// Initializes a new instance of the class.
public DateTimeRangePicker()
{
InitializeComponent();
}
/// Gets or sets the start date and time.
public DateTimeOffset? StartDateTime
{
get => GetValue(StartDateTimeProperty);
set => SetValue(StartDateTimeProperty, value);
}
/// Gets or sets the end date and time.
public DateTimeOffset? EndDateTime
{
get => GetValue(EndDateTimeProperty);
set => SetValue(EndDateTimeProperty, value);
}
/// Gets or sets the start date/time as formatted text.
public string StartText
{
get => GetValue(StartTextProperty);
set => SetValue(StartTextProperty, value);
}
/// Gets or sets the end date/time as formatted text.
public string EndText
{
get => GetValue(EndTextProperty);
set => SetValue(EndTextProperty, 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