Skip to content

Commit

Permalink
TextAlignment property added to NumberBox (#2901)
Browse files Browse the repository at this point in the history
* TextAlignment property added

* XAML Formatting reverted

* Fixed the invalid default value for TextAlignment. This was Center, is now Left. Also added the TextAlignment properties in the Test app.

* TextAlignment combobox added to the NumberBoxPage for testing.

* Marked TextAlignment as a Preview API in the IDL file

* NumberBox default TextAlignment set to Left and TextAlignmentProperty marked as Preview

* Reverted the formatting of the NumberBoxPage.xaml and implemented the TextAlignment default value using an attribute in the idl.

* Revert "Reverted the formatting of the NumberBoxPage.xaml and implemented the TextAlignment default value using an attribute in the idl."

This reverts commit 2410590.

* Reverted tne formatting caused by XAML Styler

* Default Left TextAlligment

* Add a TextAlignment API test

Co-authored-by: Stephen Peters <[email protected]>
  • Loading branch information
sonnemaf and StephenLPeters authored Aug 11, 2020
1 parent 3a6aa22 commit fb87bec
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 10 deletions.
28 changes: 27 additions & 1 deletion dev/Generated/NumberBox.properties.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
Expand Down Expand Up @@ -29,6 +29,7 @@ GlobalDependencyProperty NumberBoxProperties::s_SelectionHighlightColorProperty{
GlobalDependencyProperty NumberBoxProperties::s_SmallChangeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_SpinButtonPlacementModeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_TextProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_TextAlignmentProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_TextReadingOrderProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_ValidationModeProperty{ nullptr };
GlobalDependencyProperty NumberBoxProperties::s_ValueProperty{ nullptr };
Expand Down Expand Up @@ -217,6 +218,17 @@ void NumberBoxProperties::EnsureProperties()
ValueHelper<winrt::hstring>::BoxedDefaultValue(),
winrt::PropertyChangedCallback(&OnTextPropertyChanged));
}
if (!s_TextAlignmentProperty)
{
s_TextAlignmentProperty =
InitializeDependencyProperty(
L"TextAlignment",
winrt::name_of<winrt::TextAlignment>(),
winrt::name_of<winrt::NumberBox>(),
false /* isAttached */,
ValueHelper<winrt::TextAlignment>::BoxValueIfNecessary(winrt::TextAlignment::Left),
nullptr);
}
if (!s_TextReadingOrderProperty)
{
s_TextReadingOrderProperty =
Expand Down Expand Up @@ -270,6 +282,7 @@ void NumberBoxProperties::ClearProperties()
s_SmallChangeProperty = nullptr;
s_SpinButtonPlacementModeProperty = nullptr;
s_TextProperty = nullptr;
s_TextAlignmentProperty = nullptr;
s_TextReadingOrderProperty = nullptr;
s_ValidationModeProperty = nullptr;
s_ValueProperty = nullptr;
Expand Down Expand Up @@ -583,6 +596,19 @@ winrt::hstring NumberBoxProperties::Text()
return ValueHelper<winrt::hstring>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_TextProperty));
}

void NumberBoxProperties::TextAlignment(winrt::TextAlignment const& value)
{
[[gsl::suppress(con)]]
{
static_cast<NumberBox*>(this)->SetValue(s_TextAlignmentProperty, ValueHelper<winrt::TextAlignment>::BoxValueIfNecessary(value));
}
}

winrt::TextAlignment NumberBoxProperties::TextAlignment()
{
return ValueHelper<winrt::TextAlignment>::CastOrUnbox(static_cast<NumberBox*>(this)->GetValue(s_TextAlignmentProperty));
}

void NumberBoxProperties::TextReadingOrder(winrt::TextReadingOrder const& value)
{
[[gsl::suppress(con)]]
Expand Down
5 changes: 5 additions & 0 deletions dev/Generated/NumberBox.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class NumberBoxProperties
void Text(winrt::hstring const& value);
winrt::hstring Text();

void TextAlignment(winrt::TextAlignment const& value);
winrt::TextAlignment TextAlignment();

void TextReadingOrder(winrt::TextReadingOrder const& value);
winrt::TextReadingOrder TextReadingOrder();

Expand All @@ -82,6 +85,7 @@ class NumberBoxProperties
static winrt::DependencyProperty SmallChangeProperty() { return s_SmallChangeProperty; }
static winrt::DependencyProperty SpinButtonPlacementModeProperty() { return s_SpinButtonPlacementModeProperty; }
static winrt::DependencyProperty TextProperty() { return s_TextProperty; }
static winrt::DependencyProperty TextAlignmentProperty() { return s_TextAlignmentProperty; }
static winrt::DependencyProperty TextReadingOrderProperty() { return s_TextReadingOrderProperty; }
static winrt::DependencyProperty ValidationModeProperty() { return s_ValidationModeProperty; }
static winrt::DependencyProperty ValueProperty() { return s_ValueProperty; }
Expand All @@ -102,6 +106,7 @@ class NumberBoxProperties
static GlobalDependencyProperty s_SmallChangeProperty;
static GlobalDependencyProperty s_SpinButtonPlacementModeProperty;
static GlobalDependencyProperty s_TextProperty;
static GlobalDependencyProperty s_TextAlignmentProperty;
static GlobalDependencyProperty s_TextReadingOrderProperty;
static GlobalDependencyProperty s_ValidationModeProperty;
static GlobalDependencyProperty s_ValueProperty;
Expand Down
20 changes: 20 additions & 0 deletions dev/NumberBox/APITests/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ namespace Windows.UI.Xaml.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
13 changes: 13 additions & 0 deletions dev/NumberBox/NumberBox.idl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
String PlaceholderText;
Windows.UI.Xaml.Controls.Primitives.FlyoutBase SelectionFlyout;
Windows.UI.Xaml.Media.SolidColorBrush SelectionHighlightColor;

[WUXC_VERSION_PREVIEW]
{
[MUX_DEFAULT_VALUE("winrt::TextAlignment::Left")]
Windows.UI.Xaml.TextAlignment TextAlignment;
}

Windows.UI.Xaml.TextReadingOrder TextReadingOrder;
Boolean PreventKeyboardDisplayOnProgrammaticFocus;
Object Description;
Expand Down Expand Up @@ -98,6 +105,12 @@ unsealed runtimeclass NumberBox : Windows.UI.Xaml.Controls.Control
static Windows.UI.Xaml.DependencyProperty PlaceholderTextProperty{ get; };
static Windows.UI.Xaml.DependencyProperty SelectionFlyoutProperty{ get; };
static Windows.UI.Xaml.DependencyProperty SelectionHighlightColorProperty{ get; };

[WUXC_VERSION_PREVIEW]
{
static Windows.UI.Xaml.DependencyProperty TextAlignmentProperty{ get; };
}

static Windows.UI.Xaml.DependencyProperty TextReadingOrderProperty{ get; };
static Windows.UI.Xaml.DependencyProperty PreventKeyboardDisplayOnProgrammaticFocusProperty{ get; };
static Windows.UI.Xaml.DependencyProperty DescriptionProperty{ get; };
Expand Down
17 changes: 9 additions & 8 deletions dev/NumberBox/NumberBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<VisualStateGroup x:Name="SpinButtonStates">
<VisualState x:Name="SpinButtonsCollapsed" />

<VisualState x:Name="SpinButtonsVisible">
<VisualState.Setters>
<Setter Target="DownSpinButton.Visibility" Value="Visible" />
<Setter Target="UpSpinButton.Visibility" Value="Visible" />
<contract7Present:Setter Target="InputBox.CornerRadius" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="SpinButtonsVisible">
<VisualState.Setters>
<Setter Target="DownSpinButton.Visibility" Value="Visible" />
<Setter Target="UpSpinButton.Visibility" Value="Visible" />
<contract7Present:Setter Target="InputBox.CornerRadius" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}" />
</VisualState.Setters>
</VisualState>

<VisualState x:Name="SpinButtonsPopup">
<VisualState.Setters>
Expand Down Expand Up @@ -93,7 +93,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -125,6 +125,7 @@
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontFamily="{TemplateBinding FontFamily}"
TextAlignment="{TemplateBinding TextAlignment}"
contract7Present:CornerRadius="{TemplateBinding CornerRadius}" />

<Popup x:Name="UpDownPopup"
Expand Down
8 changes: 7 additions & 1 deletion dev/NumberBox/TestUI/NumberBoxPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<local:TestPage
x:Class="MUXControlsTestApp.NumberBoxPage"
x:Name="NumberBoxTestPage"
Expand Down Expand Up @@ -31,6 +31,12 @@
<ComboBoxItem Content="Inline"/>
</ComboBox>

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

<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 dev/NumberBox/TestUI/NumberBoxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 fb87bec

Please sign in to comment.