Adding PlateView fromm UWP project

This commit is contained in:
Selim Mustafaev 2023-10-30 23:32:26 +03:00
parent 6d85cf53c9
commit fa59e9d280
7 changed files with 148 additions and 4 deletions

View File

@ -6,9 +6,11 @@
RequestedThemeVariant="Default">
<Application.Styles>
<!--
<FluentTheme/>
-->
<sty:FluentAvaloniaTheme />
</Application.Styles>
<Application.Resources>
<FontFamily x:Key="RoadNumbersFont">avares://Assets/Fonts/RoadNumbers2.0.otf</FontFamily>
</Application.Resources>
</Application>

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,7 @@
xmlns:utils="using:AutoCat.Utils"
xmlns:vm="using:AutoCat.ViewModels"
xmlns:mocks="using:AutoCat.Mocks"
xmlns:views="using:AutoCat.Views"
mc:Ignorable="d" d:DesignWidth="350" d:DesignHeight="550"
x:Class="AutoCat.Pages.HistoryListPage"
x:DataType="vm:HistoryListViewModel"
@ -20,7 +21,7 @@
<TextBlock Text="{Binding Brand.Name.Original}"/>
</Grid>
<Grid ColumnDefinitions="* Auto" RowDefinitions="* *">
<TextBlock Grid.RowSpan="2" Text="{Binding Number}"/>
<views:PlateView Grid.RowSpan="2" Number="{Binding Number}"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding UpdatedDate}"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding AddedDate}"/>
</Grid>

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace AutoCat.Views;
//[CreateFromString(MethodName = "AutoCat.Controls.PlateNumber.ConvertFromString")]
public class PlateNumber
{
private readonly string _number;
private readonly string _numberEnglish;
private readonly Dictionary<char, char> _lettersMap = new()
{
{ 'А', 'A' }, { 'В', 'B' }, { 'Е', 'E' }, { 'К', 'K' },
{ 'М', 'M' }, { 'Н', 'H' }, { 'О', 'O' }, { 'Р', 'P' },
{ 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' }
};
private PlateNumber(string number)
{
this._number = number;
this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c));
}
public string AsString()
{
return _number;
}
public string MainPart()
{
return _numberEnglish[..6];
}
public string Region()
{
return _numberEnglish[6..];
}
public static PlateNumber ConvertFromString(string number)
{
return new PlateNumber(number);
}
}

View File

@ -0,0 +1,35 @@
<UserControl xmlns="https://github.com/avaloniaui"
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"
x:Class="AutoCat.Views.PlateView"
SizeChanged="UserControl_SizeChanged">
<Grid>
<Rectangle RadiusX="6" RadiusY="6" Fill="#ccc"/>
<Grid ColumnDefinitions="73*,27*">
<Grid>
<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"
FontFamily="{StaticResource RoadNumbersFont}" FontSize="{Binding Height}"/>
</Grid>
<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*">
<TextBlock Grid.Row="0" x:Name="RegionBox" VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="#ccc" FontFamily="{StaticResource RoadNumbersFont}"/>
<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"/>
<Grid Grid.Column="1" x:Name="FlagGrid" Margin="1" RowDefinitions="*,*,*">
<Rectangle Grid.Row="0" Fill="White"/>
<Rectangle Grid.Row="1" Fill="Blue"/>
<Rectangle Grid.Row="2" Fill="Red"/>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,61 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace AutoCat.Views;
public partial class PlateView : UserControl
{
#region Dependency properties
public static readonly StyledProperty<PlateNumber> NumberProperty =
AvaloniaProperty.Register<PlateView, PlateNumber>(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;
}
}