Skip to content

Commit

Permalink
fix: Revert "fix: Add and apply NumberBox CommonStates"
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Sep 17, 2021
1 parent 1a49525 commit 82116b4
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 1,761 deletions.
Expand Up @@ -41,28 +41,6 @@
<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>

<ComboBox x:Name="InputScopeComboBox"
AutomationProperties.Name="InputScopeComboBox"
Header="InputScope"
SelectedIndex="0"
SelectionChanged="InputScope_Changed">
<ComboBoxItem Content="Number" />
<ComboBoxItem Content="Default" />
<ComboBoxItem Content="CurrencyAmountAndSymbol" />
<ComboBoxItem Content="TelephoneNumber" />
<ComboBoxItem Content="Formula" />
</ComboBox>

<CheckBox x:Name="EnabledCheckBox"
AutomationProperties.Name="EnabledCheckBox"
IsChecked="True"
Expand Down Expand Up @@ -145,134 +123,45 @@
Content="Set value to NaN"
Click="SetNaNButton_Click"
Margin="0,4,0,0" />

<Button x:Name="SetTwoWayBoundValueNaNButton"
AutomationProperties.Name="SetTwoWayBoundValueNaNButton"
Content="Set two way bound value to NaN"
Click="SetTwoWayBoundNaNButton_Click" Margin="0,4,0,0" />

<Button x:Name="ToggleHeaderValueButton"
AutomationProperties.Name="ToggleHeaderValueButton"
Content="Toggle header for clipping issue"
Click="ToggleHeaderValueButton_Click"
Margin="0,4,0,0" />

<Button x:Name="ToggleHeaderTemplateValueButton"
AutomationProperties.Name="ToggleHeaderTemplateValueButton"
Content="Toggle header template"
Click="ToggleHeaderTemplateValueButton_Click"
Margin="0,4,0,0" />

</StackPanel>

<Grid Grid.Column="1">

<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
contract5Present:Spacing="4">
<!--Standard NumberBox test UI -->
<StackPanel>
<controls:NumberBox
MinWidth="150"
x:Name="TestNumberBox"
Description="Description text"
Header="TestNumberBox"
PlaceholderText="Text"
ValueChanged="NumberBoxValueChanged"
SmallChange="{x:Bind SmallChangeNumberBox.Value, Mode=OneWay}"
LargeChange="{x:Bind LargeChangeNumberBox.Value, Mode=OneWay}"
AcceptsExpression="{x:Bind ExpressionCheckBox.IsChecked.Value, Mode=OneWay}"
IsWrapEnabled="{x:Bind WrapCheckBox.IsChecked.Value, Mode=OneWay}"
IsEnabled="{x:Bind EnabledCheckBox.IsChecked.Value, Mode=OneWay}" />
<controls:NumberBox x:Name="TestNumberBox"
AutomationProperties.Name="TestNumberBox"
Header="NumberBox"
PlaceholderText="Text"
ValueChanged="NumberBoxValueChanged"
SmallChange="{x:Bind SmallChangeNumberBox.Value, Mode=OneWay}"
LargeChange="{x:Bind LargeChangeNumberBox.Value, Mode=OneWay}"
AcceptsExpression="{x:Bind ExpressionCheckBox.IsChecked.Value, Mode=OneWay}"
IsWrapEnabled="{x:Bind WrapCheckBox.IsChecked.Value, Mode=OneWay}"
IsEnabled="{x:Bind EnabledCheckBox.IsChecked.Value, Mode=OneWay}" />

<StackPanel Orientation="Horizontal">
<TextBlock Text="Value:"
Margin="0,0,5,0" />
<TextBlock x:Name="NewValueTextBox"
AutomationProperties.Name="NewValueTextBox"
Text="0" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Text="Old Value:"
Margin="0,0,5,0" />
<TextBlock x:Name="OldValueTextBox"
AutomationProperties.Name="OldValueTextBox" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<TextBlock Text="Text:"
Margin="0,0,5,0" />
<TextBlock x:Name="TextTextBox"
AutomationProperties.Name="TextTextBox"
Text="0" />
</StackPanel>
</StackPanel>

<!-- NumberBox for nested scrolling bug(s)-->
<StackPanel Margin="30,0,0,0">
<TextBlock>NumberBox inside ScrollViewer test</TextBlock>
<ScrollViewer x:Name="ScrollviewerWithScroll" Height="50"
Width="200"
ViewChanged="ScrollviewerWithScroll_ViewChanged">
<StackPanel>
<controls:NumberBox x:Name="NumberBoxInScroller"
AutomationProperties.Name="NumberBoxInScroller"/>
<controls:NumberBox/>
<controls:NumberBox/>
</StackPanel>
</ScrollViewer>

<TextBlock x:Name="VerticalOffsetDisplayBlock" Text="0"
AutomationProperties.Name="VerticalOffsetDisplayBlock"/>
</StackPanel>

<!-- NumberBox two way binding with x:Bind -->
<StackPanel>
<controls:NumberBox Header="TwoWayBinding" x:Name="TwoWayBoundNumberBox"
Value="{x:Bind DataModelWithINPC.Value, Mode=TwoWay}" />
<TextBlock x:Name="TwoWayBoundNumberBoxValue" AutomationProperties.Name="TwoWayBoundNumberBoxValue" />
</StackPanel>

<!-- Testing alignment with textbox and without specified header -->
<StackPanel Orientation="Horizontal">
<TextBox MaxHeight="30" VerticalAlignment="Top"/>
<controls:NumberBox x:Name="HeaderTestingNumberBox" MaxHeight="32" VerticalAlignment="Top" PlaceholderText="I should not be clipped without header"/>
<controls:NumberBox x:Name="HeaderTestingNumberBoxTwo" MaxHeight="32" VerticalAlignment="Top">
<controls:NumberBox.HeaderTemplate>
<DataTemplate>
<TextBlock AutomationProperties.Name="HeaderTemplateBeforeApplayTemplateTest" Text="MyText"/>
</DataTemplate>
</controls:NumberBox.HeaderTemplate>
</controls:NumberBox>
<controls:NumberBox>
<controls:NumberBox.Header>
<TextBlock AutomationProperties.Name="HeaderBeforeApplyTemplateTest" Text="TestNumberBox"/>
</controls:NumberBox.Header>
</controls:NumberBox>
<controls:NumberBox x:Name="HeaderTemplateTestingNumberBox"/>
<TextBlock Text="Value:"
Margin="0,0,5,0" />
<TextBlock x:Name="NewValueTextBox"
AutomationProperties.Name="NewValueTextBox"
Text="0" />
</StackPanel>

<!-- FontSize propagation -->
<controls:NumberBox Header="Header text" FontSize="50"/>

<StackPanel Orientation="Horizontal" Height="50">
<controls:NumberBox PlaceholderText="Number"/>
<TextBox PlaceholderText="Text"/>
<AutoSuggestBox PlaceholderText="Auto"/>
<!--Not yet implemented in Uno. https://github.com/unoplatform/uno/issues/3848 https://github.com/unoplatform/uno/issues/81 -->
<!--<RichEditBox PlaceholderText="Rich"/>-->
<StackPanel Orientation="Horizontal">
<TextBlock Text="Old Value:"
Margin="0,0,5,0" />
<TextBlock x:Name="OldValueTextBox"
AutomationProperties.Name="OldValueTextBox" />
</StackPanel>

<!-- Property propagation -->
<StackPanel Orientation="Horizontal">
<TextBox Header="Header text" FontSize="14" Foreground="{ThemeResource SystemAccentColor}"
Padding="20" Margin="20" BorderThickness="5" BorderBrush="Red"
Height="100" Width="200"/>
<controls:NumberBox Header="Header text" FontSize="14" Foreground="{ThemeResource SystemAccentColor}" SpinButtonPlacementMode="Inline"
Padding="20" Margin="20" BorderThickness="5" BorderBrush="Red"
Height="100" Width="200"/>
<TextBlock Text="Text:"
Margin="0,0,5,0" />
<TextBlock x:Name="TextTextBox"
AutomationProperties.Name="TextTextBox"
Text="0" />
</StackPanel>
</StackPanel>
</Grid>
Expand Down
@@ -1,49 +1,33 @@
using System;
#pragma warning disable CS0105 // Using directive appeared previously in this namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;
using Windows.Globalization.NumberFormatting;
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.Automation;
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.Markup;

using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Globalization.NumberFormatting;
using Microsoft.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Shared.Microsoft_UI_Xaml_Controls.NumberBoxTests
{
[Sample("NumberBox", "WinUI", Name="MUX_Test")]
public sealed partial class MUX_Test : UserControl
{
public DataModelWithINPC DataModelWithINPC { get; set; } = new DataModelWithINPC();

public MUX_Test()
{
this.InitializeComponent();

TestNumberBox.RegisterPropertyChangedCallback(NumberBox.TextProperty, new DependencyPropertyChangedCallback(TextPropertyChanged));
}

private void InputScope_Changed(object sender, RoutedEventArgs e)
{
if (TestNumberBox != null &&
sender is ComboBox comboBox &&
comboBox.SelectedItem is ComboBoxItem item)
{
var scopeName = new InputScopeName();
scopeName.NameValue = (InputScopeNameValue)Enum.Parse(typeof(InputScopeNameValue), item.Content?.ToString() ?? string.Empty, true);

var scope = new InputScope();
scope.Names.Add(scopeName);

TestNumberBox.InputScope = scope;

// Help testing by returning focus to the NumberBox to see the keyboard change
TestNumberBox.Focus(FocusState.Keyboard);
}
}

private void SpinMode_Changed(object sender, RoutedEventArgs e)
{
if (TestNumberBox != null)
Expand All @@ -63,25 +47,6 @@ 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 = Windows.UI.Xaml.TextAlignment.Left;
}
else if (TextAlignmentComboBox.SelectedIndex == 1)
{
TestNumberBox.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
}
else if (TextAlignmentComboBox.SelectedIndex == 2)
{
TestNumberBox.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
}
}
}

private void Validation_Changed(object sender, RoutedEventArgs e)
{
if (TestNumberBox != null)
Expand Down Expand Up @@ -125,7 +90,7 @@ private void MaxValueChanged(object sender, object e)
}
}

private void NumberBoxValueChanged(object sender, NumberBoxValueChangedEventArgs e)
private void NumberBoxValueChanged(object sender, Microsoft.UI.Xaml.Controls.NumberBoxValueChangedEventArgs e)
{
if (TestNumberBox != null && NewValueTextBox != null && OldValueTextBox != null)
{
Expand Down Expand Up @@ -158,87 +123,9 @@ private void SetNaNButton_Click(object sender, RoutedEventArgs e)
TestNumberBox.Value = Double.NaN;
}

private void SetTwoWayBoundNaNButton_Click(object sender, RoutedEventArgs e)
{
DataModelWithINPC.Value = Double.NaN;
TwoWayBoundNumberBoxValue.Text = TwoWayBoundNumberBox.Value.ToString();
}

private void ToggleHeaderValueButton_Click(object sender, RoutedEventArgs e)
{
if (HeaderTestingNumberBox.Header is null)
{
var demoHeader = new TextBlock();
demoHeader.SetValue(AutomationProperties.NameProperty, "NumberBoxHeaderClippingDemoHeader");
demoHeader.Text = "Test header";
HeaderTestingNumberBox.Header = demoHeader;
}
else
{
// Switching between normal header and empty string header
if (HeaderTestingNumberBox.Header as string is null)
{
HeaderTestingNumberBox.Header = "";
}
else
{
HeaderTestingNumberBox.Header = null;
}
}
}

private void ToggleHeaderTemplateValueButton_Click(object sender, RoutedEventArgs e)
{
if (HeaderTemplateTestingNumberBox.HeaderTemplate is null)
{
string templateString =
@"<DataTemplate
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<TextBlock AutomationProperties.Name=""HeaderTemplateTestingBlock"" Text=""Some text""/>
</DataTemplate>";
HeaderTemplateTestingNumberBox.HeaderTemplate = XamlReader.Load(templateString) as DataTemplate;
}
else
{
// Switching between normal header and empty string header
HeaderTemplateTestingNumberBox.HeaderTemplate = null;
}
}

private void TextPropertyChanged(DependencyObject o, DependencyProperty p)
{
TextTextBox.Text = TestNumberBox.Text;
}

private void ScrollviewerWithScroll_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
VerticalOffsetDisplayBlock.Text = (sender as Windows.UI.Xaml.Controls.ScrollViewer).VerticalOffset.ToString();
}
}

public class DataModelWithINPC : INotifyPropertyChanged
{
private double _value;

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public double Value
{
get => _value;
set
{
if (value != _value)
{
_value = value;
OnPropertyChanged(nameof(this.Value));
}
}
}

}
}

0 comments on commit 82116b4

Please sign in to comment.