Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextAlignment property added to NumberBox #2901

Merged
merged 11 commits into from
Aug 11, 2020
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to include static Windows.UI.Xaml.DependencyProperty TextAlignmentProperty{ get; }; here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, makes sense.

{
[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 @@ -23,13 +23,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 @@ -85,7 +85,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -117,6 +117,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