82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using AutoCatCore.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using Windows.Foundation;
|
|
using Windows.Foundation.Collections;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
using Windows.UI.Xaml.Controls.Primitives;
|
|
using Windows.UI.Xaml.Data;
|
|
using Windows.UI.Xaml.Input;
|
|
using Windows.UI.Xaml.Media;
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
|
|
|
namespace AutoCat.Controls
|
|
{
|
|
public sealed partial class PlateView : UserControl
|
|
{
|
|
#region Dependency properties
|
|
|
|
public static readonly DependencyProperty NumberProperty = DependencyProperty.Register("Number", typeof(PlateNumber), typeof(PlateView), new PropertyMetadata(null, OnNumberChanged));
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public PlateNumber Number
|
|
{
|
|
get { return (PlateNumber)GetValue(NumberProperty); }
|
|
set { SetValue(NumberProperty, value); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
private double aspectRatio = 112.0 / 520.0;
|
|
|
|
public PlateView()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
private static void OnNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if(d is PlateView plateNumber && e.NewValue is PlateNumber number)
|
|
{
|
|
plateNumber.NumberBox.Text = number.MainPart();
|
|
plateNumber.RegionBox.Text = number.Region();
|
|
}
|
|
}
|
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
{
|
|
var newAspect = availableSize.Height / availableSize.Width;
|
|
var newSize = availableSize;
|
|
if (newAspect >= aspectRatio)
|
|
{
|
|
newSize = new Size(availableSize.Width, availableSize.Width * aspectRatio);
|
|
}
|
|
else
|
|
{
|
|
newSize = new Size(availableSize.Height / aspectRatio, availableSize.Height);
|
|
}
|
|
|
|
return newSize;
|
|
}
|
|
|
|
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.ActualHeight * 1.5;
|
|
CountryName.FontSize = CountryRow.ActualHeight;
|
|
}
|
|
}
|
|
}
|