Skip to content

Commit

Permalink
feat(progressbar): Added WinUI 2.3 ProgressBar first implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Jun 16, 2020
1 parent 3427e7a commit 195af14
Show file tree
Hide file tree
Showing 10 changed files with 907 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
Expand All @@ -16,17 +15,16 @@
using Windows.UI.Xaml.Navigation;
using Windows.Globalization.NumberFormatting;
using Microsoft.UI.Xaml.Controls;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
using Uno.UI.Samples.Controls;

namespace UITests.Shared.Microsoft_UI_Xaml_Controls.NumberBoxTests
{
[SampleControlInfo("NumberBox", "MUX_Test")]
[Sample("NumberBox", "WinUI", Name="MUX_Test")]
public sealed partial class MUX_Test : UserControl
{
public MUX_Test()
{
this.InitializeComponent();
{
public MUX_Test()
{
this.InitializeComponent();
#if HAS_UNO
TestNumberBox.RegisterPropertyChangedCallback(NumberBox.TextProperty, new DependencyPropertyChangedCallback(TextPropertyChanged));
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace UITests.Microsoft_UI_Xaml_Controls.NumberBoxTests
{
[SampleControlInfo(category: "NumberBox")]
[Sample("NumberBox", "WinUI")]
public sealed partial class NumberBox_ExpressionTest : Page
{
const double resetValue = double.NaN;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<Page
x:Class="UITests.Microsoft_UI_Xaml_Controls.ProgressBar.WinUIProgressBarPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:Uno.UI.Samples.Converters"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Page.Resources>
<converters:FromNullableBoolToDefaultValueConverter x:Key="NullableBooleanToBooleanConverter">
<converters:FromNullableBoolToDefaultValueConverter.TrueValue>
<x:Boolean>True</x:Boolean>
</converters:FromNullableBoolToDefaultValueConverter.TrueValue>
<converters:FromNullableBoolToDefaultValueConverter.NullOrFalseValue>
<x:Boolean>False</x:Boolean>
</converters:FromNullableBoolToDefaultValueConverter.NullOrFalseValue>
</converters:FromNullableBoolToDefaultValueConverter>
</Page.Resources>

<Grid Margin="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<StackPanel Grid.ColumnSpan="3" Orientation="Horizontal">
<TextBlock Text="Sample Progressbar"/>
<FontIcon Glyph="&#xF0AF;" Margin="4,0,40,3" FontSize="14" VerticalAlignment="Center"/>
<controls:ProgressBar
x:Name="TestProgressBar"
Width="100"
VerticalAlignment="Center"
AutomationProperties.Name="TestProgressBar"
HorizontalAlignment="Left"
IsIndeterminate="{x:Bind ShowIsDeterminateCheckBox.IsChecked, Converter={StaticResource NullableBooleanToBooleanConverter}, Mode=OneWay}"
ShowPaused="{x:Bind ShowPausedCheckBox.IsChecked, Converter={StaticResource NullableBooleanToBooleanConverter}, Mode=OneWay}"
ShowError="{x:Bind ShowErrorCheckBox.IsChecked, Converter={StaticResource NullableBooleanToBooleanConverter}, Mode=OneWay}"/>
</StackPanel>

<StackPanel Grid.Row="1">
<StackPanel>
<TextBlock Text="Options"/>
<Grid Width="300" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBox x:Name="MaximumInput" AutomationProperties.Name="MaximumInput" Header="Maximum" PlaceholderText="100" Width="90" HorizontalAlignment="Left" Grid.ColumnSpan="1"/>
<TextBlock x:Name="MaximumInputText" AutomationProperties.Name="MaximumInputText" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Maximum, Mode=TwoWay}"/>

<TextBox x:Name="MinimumInput" AutomationProperties.Name="MinimumInput" Header="Minimum" PlaceholderText="0" Width="90" HorizontalAlignment="Left" Grid.Row="1" Grid.ColumnSpan="1"/>
<TextBlock x:Name="MinimumInputText" AutomationProperties.Name="MinimumInputText" Grid.Row="1" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Minimum, Mode=TwoWay}"/>

<TextBox x:Name="WidthInput" AutomationProperties.Name="WidthInput" Header="Width" PlaceholderText="0" Width="90" HorizontalAlignment="Left" Grid.Row="2" Grid.ColumnSpan="1"/>
<TextBlock x:Name="WidthInputText" AutomationProperties.Name="WidthInputText" Grid.Row="2" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Width, Mode=TwoWay}"/>

<TextBox x:Name="ValueInput" AutomationProperties.Name="ValueInput" Header="Value" PlaceholderText="0" Width="90" HorizontalAlignment="Left" Grid.Row="3" Grid.ColumnSpan="1"/>
<TextBlock x:Name="ValueText" AutomationProperties.Name="ValueText" Grid.Row="3" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Value, Mode=TwoWay}"/>
</Grid>

<TextBlock Text="Padding" Margin="0, 20, 0, 10"/>

<Grid Width="300" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBox x:Name="PaddingLeftInput" AutomationProperties.Name="PaddingLeftInput" Header="Left" PlaceholderText="0" Width="90" HorizontalAlignment="Left" Grid.Row="1" Grid.ColumnSpan="1"/>
<TextBlock x:Name="PaddingLeftText" AutomationProperties.Name="PaddingLeftText" Grid.Row="1" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Padding.Left, Mode=TwoWay}"/>

<TextBox x:Name="PaddingRightInput" AutomationProperties.Name="PaddingRightInput" Header="Right" PlaceholderText="0" Width="90" HorizontalAlignment="Left" Grid.Row="2" Grid.ColumnSpan="1"/>
<TextBlock x:Name="PaddingRightText" AutomationProperties.Name="PaddingRightText" Grid.Row="2" Grid.Column="1" Text="{Binding ElementName=TestProgressBar, Path=Padding.Right, Mode=TwoWay}"/>

</Grid>
<TextBlock Text="States"/>
<CheckBox x:Name="ShowPausedCheckBox" AutomationProperties.Name="ShowPausedCheckBox" Content="ShowPaused" />
<CheckBox x:Name="ShowErrorCheckBox" AutomationProperties.Name="ShowErrorCheckBox" Content="ShowError"/>
<CheckBox x:Name="ShowIsDeterminateCheckBox" AutomationProperties.Name="ShowIsDeterminateCheckBox" Content="IsDeterminate"/>
</StackPanel>

<StackPanel Margin="0,16,0,0">
<TextBlock Text="Actions"/>
<Button x:Name="UpdateMinMaxButton" AutomationProperties.Name="UpdateMinMaxButton" Content="Update Min and Max" Click="UpdateMinMax_Click"/>
<Button x:Name="UpdateWidthButton" AutomationProperties.Name="UpdateWidthButton" Content="Update Width" Click="UpdateWidth_Click"/>
<Button x:Name="UpdateValueButton" AutomationProperties.Name="UpdateValueButton" Content="Update Value" Click="UpdateValue_Click"/>
<RepeatButton x:Name="ChangeValueButton" AutomationProperties.Name="ChangeValueButton" Content="Hold and Change Value" Click="ChangeValue_Click" />
<Button x:Name="UpdatePaddingButton" AutomationProperties.Name="UpdatePaddingButton" Content="Update Padding Left and Right" Click="UpdatePadding_Click"/>
</StackPanel>

</StackPanel>

<StackPanel Grid.Column="1" Grid.Row="1" Margin="16,0,0,0">
<TextBlock Text="Properties" />

<TextBlock Text="Indicator Width" Margin="0, 20, 0, 0"/>
<TextBlock x:Name="IndicatorWidthText" AutomationProperties.Name="IndicatorWidthText" Margin="0, 0, 0, 20"/>

<TextBlock Text="Is paused:" Margin="0, 20, 0, 0" FontSize="20"/>
<TextBlock AutomationProperties.Name="ShowPausedText" Text="{x:Bind ShowPausedCheckBox.IsChecked, Mode=OneWay}"/>

<TextBlock Text="Is error:" Margin="0, 20, 0, 0" FontSize="20"/>
<TextBlock AutomationProperties.Name="ShowErrorText" Text="{x:Bind ShowErrorCheckBox.IsChecked, Mode=OneWay}"/>

<TextBlock Text="Is indeterminate:" Margin="0, 20, 0, 0" FontSize="20"/>
<TextBlock AutomationProperties.Name="ShowIsDeterminateText" Text="{x:Bind ShowIsDeterminateCheckBox.IsChecked, Mode=OneWay}"/>

<TextBlock x:Name="VisualStateText" AutomationProperties.Name="VisualStateText" Margin="0, 20, 0, 0"/>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml.Shapes;

namespace UITests.Microsoft_UI_Xaml_Controls.ProgressBar
{
[Sample("ProgressBar", "WinUI")]
public sealed partial class WinUIProgressBarPage : Page
{
public WinUIProgressBarPage()
{
this.InitializeComponent();
Loaded += ProgressBarPage_Loaded;
}

private void ProgressBarPage_Loaded(object sender, RoutedEventArgs e)
{
var layoutRoot = (Grid)VisualTreeHelper.GetChild(TestProgressBar, 0);

VisualStateManager.GetVisualStateGroups(layoutRoot)[0].CurrentStateChanged += this.ProgressBarPage_CurrentStateChanged;
VisualStateText.Text = VisualStateManager.GetVisualStateGroups(layoutRoot)[0].CurrentState.Name;

var progressBarRoot = VisualTreeHelper.GetChild(layoutRoot, 0);
var clip = VisualTreeHelper.GetChild(progressBarRoot, 0);
var stackPanel = VisualTreeHelper.GetChild(clip, 0);
var indicator = (Rectangle)VisualTreeHelper.GetChild(stackPanel, 0);

if (indicator != null)
{
indicator.SizeChanged += this.Indicator_SizeChanged;
IndicatorWidthText.Text = indicator.ActualWidth.ToString();
}

Loaded -= ProgressBarPage_Loaded;
}

private void Indicator_SizeChanged(object sender, SizeChangedEventArgs e)
{
IndicatorWidthText.Text = ((Rectangle)sender).ActualWidth.ToString();
}

private void ProgressBarPage_CurrentStateChanged(object sender, VisualStateChangedEventArgs e)
{
VisualStateText.Text = e.NewState.Name;
}

public void UpdateMinMax_Click(object sender, RoutedEventArgs e)
{
TestProgressBar.Maximum = String.IsNullOrEmpty(MaximumInput.Text) ? Double.Parse(MaximumInput.PlaceholderText) : Double.Parse(MaximumInput.Text);
TestProgressBar.Minimum = String.IsNullOrEmpty(MinimumInput.Text) ? Double.Parse(MinimumInput.PlaceholderText) : Double.Parse(MinimumInput.Text);
}

public void UpdateWidth_Click(object sender, RoutedEventArgs e)
{
TestProgressBar.Width = String.IsNullOrEmpty(WidthInput.Text) ? Double.Parse(WidthInput.PlaceholderText) : Double.Parse(WidthInput.Text);
}

public void UpdateValue_Click(object sender, RoutedEventArgs e)
{
TestProgressBar.Value = String.IsNullOrEmpty(ValueInput.Text) ? Double.Parse(ValueInput.PlaceholderText) : Double.Parse(ValueInput.Text);
}

public void ChangeValue_Click(object sender, RoutedEventArgs e)
{
if (TestProgressBar.Value + 1 > TestProgressBar.Maximum)
{
TestProgressBar.Value = (int)(TestProgressBar.Minimum + 0.5);
}
else
{
TestProgressBar.Value += 1;
}
}

public void UpdatePadding_Click(object sender, RoutedEventArgs e)
{
double paddingLeft = String.IsNullOrEmpty(PaddingLeftInput.Text) ? Double.Parse(PaddingLeftInput.PlaceholderText) : Double.Parse(PaddingLeftInput.Text);
double paddingRight = String.IsNullOrEmpty(PaddingRightInput.Text) ? Double.Parse(PaddingRightInput.PlaceholderText) : Double.Parse(PaddingRightInput.Text);

TestProgressBar.Padding = new Thickness(paddingLeft, 0, paddingRight, 0);
}
}

public class NullableBooleanToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return value is bool ? (bool)value : (object)false;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value is bool ? (bool)value : (object)false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace UITests.Shared.Microsoft_UI_Xaml_Controls.TwoPaneViewTests
{
[SampleControlInfo("TwoPaneView", "MUX_Test")]
[Sample("TwoPaneView", "WinUI", Name="MUX_Test")]
public sealed partial class TwoPaneViewPage : Page
{
// Need to be the same as c_defaultMinWideModeWidth/c_defaultMinTallModeHeight in TwoPaneViewFactory.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressBar\WinUIProgressBarPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\TwoPaneViewTests\TwoPaneViewPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3261,6 +3265,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressRing\WinUIProgressRingPage.xaml.cs">
<DependentUpon>WinUIProgressRingPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ProgressBar\WinUIProgressBarPage.xaml.cs">
<DependentUpon>WinUIProgressBarPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\SplitButtonTests\SplitButtonPage.xaml.cs">
<DependentUpon>SplitButtonPage.xaml</DependentUpon>
</Compile>
Expand Down
Loading

0 comments on commit 195af14

Please sign in to comment.