diff --git a/AutoCat/Pages/HistoryPage.axaml b/AutoCat/Pages/HistoryPage.axaml index 0ff9a7f..c732f7a 100644 --- a/AutoCat/Pages/HistoryPage.axaml +++ b/AutoCat/Pages/HistoryPage.axaml @@ -5,7 +5,7 @@ xmlns:pages="clr-namespace:AutoCat.Pages" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AutoCat.Pages.HistoryPage"> - + diff --git a/AutoCat/Views/PlateNumber.cs b/AutoCat/Views/PlateNumber.cs index 40061ee..86c8d3b 100644 --- a/AutoCat/Views/PlateNumber.cs +++ b/AutoCat/Views/PlateNumber.cs @@ -17,7 +17,7 @@ public class PlateNumber { 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' } }; - private PlateNumber(string number) + public PlateNumber(string number) { this._number = number; this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c)); diff --git a/AutoCat/Views/PlateView.axaml b/AutoCat/Views/PlateView.axaml index 61acf13..899acb2 100644 --- a/AutoCat/Views/PlateView.axaml +++ b/AutoCat/Views/PlateView.axaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="150" x:Class="AutoCat.Views.PlateView" SizeChanged="UserControl_SizeChanged"> @@ -13,13 +13,13 @@ + FontSize="{Binding Height}"/> + Foreground="#ccc"/> diff --git a/AutoCat/Views/PlateView.axaml.cs b/AutoCat/Views/PlateView.axaml.cs index b1eff0a..75e0731 100644 --- a/AutoCat/Views/PlateView.axaml.cs +++ b/AutoCat/Views/PlateView.axaml.cs @@ -1,5 +1,7 @@ +using System; using Avalonia; using Avalonia.Controls; +using Avalonia.Data; using Avalonia.Markup.Xaml; namespace AutoCat.Views; @@ -7,17 +9,17 @@ namespace AutoCat.Views; public partial class PlateView : UserControl { #region Dependency properties - - public static readonly StyledProperty NumberProperty = - AvaloniaProperty.Register(nameof(Number), inherits: true); + + public static readonly StyledProperty NumberProperty = + AvaloniaProperty.Register(nameof(Number)); #endregion #region Properties - - public PlateNumber Number + + public string Number { - get => (PlateNumber)GetValue(NumberProperty); + get => (string)GetValue(NumberProperty); set => SetValue(NumberProperty, value); } @@ -25,21 +27,25 @@ public partial class PlateView : UserControl private const double AspectRatio = 112.0 / 520.0; + static PlateView() + { + NumberProperty.Changed.AddClassHandler((v, e) => v.NumberChanged(e)); + } + public PlateView() { InitializeComponent(); } - - /* - private static void OnNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + + private void NumberChanged(AvaloniaPropertyChangedEventArgs e) { - if (d is not PlateView plateNumber || e.NewValue is not PlateNumber number) + if (e.NewValue is not string newNumber) return; - plateNumber.NumberBox.Text = number.MainPart(); - plateNumber.RegionBox.Text = number.Region(); + var number = new PlateNumber(newNumber); + NumberBox.Text = number.MainPart(); + RegionBox.Text = number.Region(); } - */ protected override Size MeasureOverride(Size availableSize) { @@ -56,6 +62,10 @@ public partial class PlateView : UserControl 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; + + if (CountryRow.Height > 0) + { + CountryName.FontSize = CountryRow.Height; + } } } \ No newline at end of file