Adding PlateNumber control

This commit is contained in:
Selim Mustafaev 2023-11-06 21:32:58 +03:00
parent fa59e9d280
commit 44e229070f
4 changed files with 29 additions and 19 deletions

View File

@ -5,7 +5,7 @@
xmlns:pages="clr-namespace:AutoCat.Pages" xmlns:pages="clr-namespace:AutoCat.Pages"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AutoCat.Pages.HistoryPage"> x:Class="AutoCat.Pages.HistoryPage">
<Grid ColumnDefinitions="300, Auto, *"> <Grid ColumnDefinitions="400, Auto, *">
<pages:HistoryListPage/> <pages:HistoryListPage/>
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/> <GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
<pages:ReportPage Grid.Column="2"/> <pages:ReportPage Grid.Column="2"/>

View File

@ -17,7 +17,7 @@ public class PlateNumber
{ 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' } { 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' }
}; };
private PlateNumber(string number) public PlateNumber(string number)
{ {
this._number = number; this._number = number;
this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c)); this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c));

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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" x:Class="AutoCat.Views.PlateView"
SizeChanged="UserControl_SizeChanged"> SizeChanged="UserControl_SizeChanged">
@ -13,13 +13,13 @@
<Grid> <Grid>
<Rectangle Grid.Column="0" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="2"/> <Rectangle Grid.Column="0" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="2"/>
<TextBlock x:Name="NumberBox" Text="A123AA" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#ccc" <TextBlock x:Name="NumberBox" Text="A123AA" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#ccc"
FontFamily="{StaticResource RoadNumbersFont}" FontSize="{Binding Height}"/> FontSize="{Binding Height}"/>
</Grid> </Grid>
<Rectangle Grid.Column="1" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="0,2,2,2"/> <Rectangle Grid.Column="1" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="0,2,2,2"/>
<Grid Grid.Column="1" Margin="0,2,2,2" RowDefinitions="65*,35*"> <Grid Grid.Column="1" Margin="0,2,2,2" RowDefinitions="65*,35*">
<TextBlock Grid.Row="0" x:Name="RegionBox" VerticalAlignment="Center" HorizontalAlignment="Center" <TextBlock Grid.Row="0" x:Name="RegionBox" VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="#ccc" FontFamily="{StaticResource RoadNumbersFont}"/> Foreground="#ccc"/>
<Grid Grid.Row="1" Margin="3,1" x:Name="CountryRow" ColumnDefinitions="*,Auto"> <Grid Grid.Row="1" Margin="3,1" x:Name="CountryRow" ColumnDefinitions="*,Auto">
<TextBlock Grid.Column="0" x:Name="CountryName" Text="RUS" VerticalAlignment="Center" TextAlignment="Center"/> <TextBlock Grid.Column="0" x:Name="CountryName" Text="RUS" VerticalAlignment="Center" TextAlignment="Center"/>
<Grid Grid.Column="1" x:Name="FlagGrid" Margin="1" RowDefinitions="*,*,*"> <Grid Grid.Column="1" x:Name="FlagGrid" Margin="1" RowDefinitions="*,*,*">

View File

@ -1,5 +1,7 @@
using System;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
namespace AutoCat.Views; namespace AutoCat.Views;
@ -8,16 +10,16 @@ public partial class PlateView : UserControl
{ {
#region Dependency properties #region Dependency properties
public static readonly StyledProperty<PlateNumber> NumberProperty = public static readonly StyledProperty<string> NumberProperty =
AvaloniaProperty.Register<PlateView, PlateNumber>(nameof(Number), inherits: true); AvaloniaProperty.Register<PlateView, string>(nameof(Number));
#endregion #endregion
#region Properties #region Properties
public PlateNumber Number public string Number
{ {
get => (PlateNumber)GetValue(NumberProperty); get => (string)GetValue(NumberProperty);
set => SetValue(NumberProperty, value); set => SetValue(NumberProperty, value);
} }
@ -25,21 +27,25 @@ public partial class PlateView : UserControl
private const double AspectRatio = 112.0 / 520.0; private const double AspectRatio = 112.0 / 520.0;
static PlateView()
{
NumberProperty.Changed.AddClassHandler<PlateView>((v, e) => v.NumberChanged(e));
}
public PlateView() public PlateView()
{ {
InitializeComponent(); InitializeComponent();
} }
/* private void NumberChanged(AvaloniaPropertyChangedEventArgs e)
private static void OnNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
if (d is not PlateView plateNumber || e.NewValue is not PlateNumber number) if (e.NewValue is not string newNumber)
return; return;
plateNumber.NumberBox.Text = number.MainPart(); var number = new PlateNumber(newNumber);
plateNumber.RegionBox.Text = number.Region(); NumberBox.Text = number.MainPart();
RegionBox.Text = number.Region();
} }
*/
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
@ -56,6 +62,10 @@ public partial class PlateView : UserControl
RegionBox.FontSize = e.NewSize.Height * 0.65; RegionBox.FontSize = e.NewSize.Height * 0.65;
RegionBox.Margin = new Thickness(0, -RegionBox.FontSize * 0.3, 0, 0); RegionBox.Margin = new Thickness(0, -RegionBox.FontSize * 0.3, 0, 0);
FlagGrid.Width = FlagGrid.Height * 1.5; FlagGrid.Width = FlagGrid.Height * 1.5;
if (CountryRow.Height > 0)
{
CountryName.FontSize = CountryRow.Height; CountryName.FontSize = CountryRow.Height;
} }
}
} }