using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; namespace AutoCat.Views; public partial class PlateView : UserControl { #region Dependency properties public static readonly StyledProperty NumberProperty = AvaloniaProperty.Register(nameof(Number), inherits: true); #endregion #region Properties public PlateNumber Number { get => (PlateNumber)GetValue(NumberProperty); set => SetValue(NumberProperty, value); } #endregion private const double AspectRatio = 112.0 / 520.0; public PlateView() { InitializeComponent(); } /* private static void OnNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is not PlateView plateNumber || e.NewValue is not PlateNumber number) return; plateNumber.NumberBox.Text = number.MainPart(); plateNumber.RegionBox.Text = number.Region(); } */ protected override Size MeasureOverride(Size availableSize) { var newAspect = availableSize.Height / availableSize.Width; return newAspect >= AspectRatio ? new Size(availableSize.Width, availableSize.Width * AspectRatio) : new Size(availableSize.Height / AspectRatio, availableSize.Height); } private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) { NumberBox.Margin = new Thickness(0, -e.NewSize.Height * 0.35, 0, 0); RegionBox.FontSize = e.NewSize.Height * 0.65; RegionBox.Margin = new Thickness(0, -RegionBox.FontSize * 0.3, 0, 0); FlagGrid.Width = FlagGrid.Height * 1.5; CountryName.FontSize = CountryRow.Height; } }