Fix alignment of number pad buttons.

This commit is contained in:
Lê Duy Quang 2024-10-06 22:14:31 +07:00
commit a5237d4ed6
No known key found for this signature in database
GPG key ID: 587F4F0F59EBA89F
4 changed files with 44 additions and 3 deletions

View file

@ -727,7 +727,8 @@
Grid.Row="2"
Grid.RowSpan="4"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
ButtonStyle="{StaticResource NumericButtonStyle18}"
CurrentRadixType="{x:Bind Model.CurrentRadixType, Mode=OneWay}"/>
</Grid>

View file

@ -1303,7 +1303,8 @@
Grid.Row="4"
Grid.RowSpan="4"
Grid.Column="1"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
AutomationProperties.HeadingLevel="Level1"
AutomationProperties.Name="{utils:ResourceString Name=NumberPad/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
ButtonStyle="{StaticResource NumericButtonStyle24}"/>

View file

@ -329,7 +329,8 @@
Grid.Row="2"
Grid.RowSpan="4"
Grid.Column="2"
Grid.ColumnSpan="3"
Grid.ColumnSpan="4"
ExtraColumns="1"
AutomationProperties.HeadingLevel="Level1"
AutomationProperties.Name="{utils:ResourceString Name=NumberPad/[using:Windows.UI.Xaml.Automation]AutomationProperties/Name}"
ButtonStyle="{StaticResource NumericButtonStyle24}"/>

View file

@ -1,5 +1,6 @@
using CalculatorApp.ViewModel.Common;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@ -29,6 +30,20 @@ namespace CalculatorApp
Num9Button.Content = localizationSettings.GetDigitSymbolFromEnUsDigit('9');
}
// Extra empty columns to the right so that column widths are calculated consistently with the rest of the button panel.
public int ExtraColumns
{
get => (int)GetValue(ExtraColumnsProperty);
set => SetValue(ExtraColumnsProperty, value);
}
public static readonly DependencyProperty ExtraColumnsProperty =
DependencyProperty.Register(nameof(ExtraColumns), typeof(int), typeof(NumberPad), new PropertyMetadata(0, (sender, args) =>
{
((NumberPad)sender).OnExtraColumnsPropertyChanged((int)args.OldValue, (int)args.NewValue);
}));
public Windows.UI.Xaml.Style ButtonStyle
{
get => (Windows.UI.Xaml.Style)GetValue(ButtonStyleProperty);
@ -67,6 +82,29 @@ namespace CalculatorApp
}
}
private void OnExtraColumnsPropertyChanged(int oldValue, int newValue)
{
if (newValue < 0)
{
throw new ArgumentException($"ExtraColumns of value {newValue} is smaller than 0.");
}
var columnDefinitions = Root.ColumnDefinitions;
if (newValue > oldValue)
{
for (int i = oldValue; i < newValue; ++i)
{
columnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
}
}
else
{
for (int i = oldValue; i > newValue; --i)
{
columnDefinitions.RemoveAt(columnDefinitions.Count - 1);
}
}
}
private void OnCurrentRadixTypePropertyChanged(NumberBase oldValue, NumberBase newValue)
{
Num0Button.IsEnabled = true;