Skip to content

Commit

Permalink
TextAlignment property added to NumberBox (microsoft/microsoft-ui-xam…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Aug 17, 2020
1 parent a6fab17 commit 7fe3563
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ModernWpf.Controls/NumberBox/NumberBox.properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ public Brush SelectionBrush

#endregion

#region TextAlignment

public static readonly DependencyProperty TextAlignmentProperty =
DependencyProperty.Register(
nameof(TextAlignment),
typeof(TextAlignment),
typeof(NumberBox),
new PropertyMetadata(TextAlignment.Left));

public TextAlignment TextAlignment
{
get => (TextAlignment)GetValue(TextAlignmentProperty);
set => SetValue(TextAlignmentProperty, value);
}

#endregion

#region Description

public static readonly DependencyProperty DescriptionProperty =
Expand Down
1 change: 1 addition & 0 deletions ModernWpf.Controls/NumberBox/NumberBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontFamily="{TemplateBinding FontFamily}"
TextAlignment="{TemplateBinding TextAlignment}"
ui:ControlHelper.CornerRadius="{TemplateBinding CornerRadius}" />

<Popup
Expand Down
20 changes: 20 additions & 0 deletions test/ModernWpfTestApp/ApiTests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ namespace ModernWpf.Tests.MUXControls.ApiTests
[TestClass]
public class NumberBoxTests : ApiTestBase
{
[TestMethod]
public void VerifyTextAlignmentPropogates()
{
var numberBox = SetupNumberBox();
TextBox textBox = null;

RunOnUIThread.Execute(() =>
{
Content.UpdateLayout();

textBox = TestUtilities.FindDescendents<TextBox>(numberBox).Where(e => e.Name == "InputBox").Single();
Verify.AreEqual(TextAlignment.Left, textBox.TextAlignment, "The default TextAlignment should be left.");

numberBox.TextAlignment = TextAlignment.Right;
Content.UpdateLayout();

Verify.AreEqual(TextAlignment.Right, textBox.TextAlignment, "The TextAlignment should have been updated to Right.");
});
}

[TestMethod]
public void VerifyNumberBoxCornerRadius()
{
Expand Down
6 changes: 6 additions & 0 deletions test/ModernWpfTestApp/NumberBoxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<ComboBoxItem Content="Inline"/>
</ComboBoxEx>

<ComboBoxEx x:Name="TextAlignmentComboBox" AutomationProperties.Name="TextAlignmentComboBox" Header="TextAlignment" SelectedIndex="0" SelectionChanged="TextAlignment_Changed">
<ComboBoxItem Content="Left" />
<ComboBoxItem Content="Center" />
<ComboBoxItem Content="Right" />
</ComboBoxEx>

<CheckBox x:Name="EnabledCheckBox" AutomationProperties.Name="EnabledCheckBox" IsChecked="True" Content="Enabled"/>

<CheckBox x:Name="ExpressionCheckBox" AutomationProperties.Name="ExpressionCheckBox" IsChecked="False" Content="Accepts Expression"/>
Expand Down
19 changes: 19 additions & 0 deletions test/ModernWpfTestApp/NumberBoxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ private void SpinMode_Changed(object sender, RoutedEventArgs e)
}
}

private void TextAlignment_Changed(object sender, RoutedEventArgs e)
{
if (TestNumberBox != null)
{
if (TextAlignmentComboBox.SelectedIndex == 0)
{
TestNumberBox.TextAlignment = TextAlignment.Left;
}
else if (TextAlignmentComboBox.SelectedIndex == 1)
{
TestNumberBox.TextAlignment = TextAlignment.Center;
}
else if (TextAlignmentComboBox.SelectedIndex == 2)
{
TestNumberBox.TextAlignment = TextAlignment.Right;
}
}
}

private void Validation_Changed(object sender, RoutedEventArgs e)
{
if (TestNumberBox != null)
Expand Down

0 comments on commit 7fe3563

Please sign in to comment.