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

Remove Dependency Properties from WinUI Stepper #1258

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 43 additions & 65 deletions src/Core/src/Platform/Windows/MauiStepper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,16 @@ namespace Microsoft.Maui
{
public class MauiStepper : Control
{
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(MauiStepper), new PropertyMetadata(default(double), OnValueChanged));

public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(double), typeof(MauiStepper), new PropertyMetadata(default(double), OnMaxMinChanged));

public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(double), typeof(MauiStepper), new PropertyMetadata(default(double), OnMaxMinChanged));

public static readonly DependencyProperty IncrementProperty =
DependencyProperty.Register("Increment", typeof(double), typeof(MauiStepper),
new PropertyMetadata(default(double), OnIncrementChanged));

public static readonly DependencyProperty ButtonBackgroundColorProperty =
DependencyProperty.Register(nameof(ButtonBackgroundColor), typeof(Color), typeof(MauiStepper), new PropertyMetadata(default(Color), OnButtonBackgroundColorChanged));

public static readonly DependencyProperty ButtonBackgroundProperty =
DependencyProperty.Register(nameof(ButtonBackgroundColor), typeof(WBrush), typeof(MauiStepper), new PropertyMetadata(default(WBrush), OnButtonBackgroundChanged));



Button _plus;
Button _minus;
VisualStateCache _plusStateCache;
VisualStateCache _minusStateCache;
double _increment;
double _value;
double _maximum;
double _minimum;
Color _buttonBackgroundColor;
WBrush _buttonBackground;

public MauiStepper()
{
Expand All @@ -48,38 +33,63 @@ public MauiStepper()

public double Increment
{
get { return (double)GetValue(IncrementProperty); }
set { SetValue(IncrementProperty, value); }
get => _increment;
set
{
_increment = value;
UpdateEnabled(Value);
}
}

public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
get => _maximum;
set
{
_maximum = value;
UpdateEnabled(Value);
}
}

public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
get => _minimum;
set
{
_minimum = value;
UpdateEnabled(Value);
}
}

public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
get => _value;
set
{
_value = value;
UpdateEnabled(value);
ValueChanged?.Invoke(this, EventArgs.Empty);
}
}

public Color ButtonBackgroundColor
{
get { return (Color)GetValue(ButtonBackgroundColorProperty); }
set { SetValue(ButtonBackgroundColorProperty, value); }
get => _buttonBackgroundColor;
set
{
_buttonBackgroundColor = value;
UpdateButtonBackgroundColor(value);
}
}

public WBrush ButtonBackground
{
get { return (WBrush)GetValue(ButtonBackgroundProperty); }
set { SetValue(ButtonBackgroundProperty, value); }
get => _buttonBackground;
set
{
_buttonBackground = value;
UpdateButtonBackground();
}
}

public event EventHandler ValueChanged;
Expand All @@ -100,30 +110,6 @@ protected override void OnApplyTemplate()
UpdateButtonBackground();
}

static void OnButtonBackgroundColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var stepper = (MauiStepper)d;
stepper.UpdateButtonBackgroundColor(stepper.ButtonBackgroundColor);
}

static void OnButtonBackgroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var stepper = (MauiStepper)d;
stepper.UpdateButtonBackground();
}

static void OnIncrementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var stepper = (MauiStepper)d;
stepper.UpdateEnabled(stepper.Value);
}

static void OnMaxMinChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var stepper = (MauiStepper)d;
stepper.UpdateEnabled(stepper.Value);
}

void OnMinusClicked(object sender, RoutedEventArgs e)
{
UpdateValue(-Increment);
Expand All @@ -134,14 +120,6 @@ void OnPlusClicked(object sender, RoutedEventArgs e)
UpdateValue(+Increment);
}

static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var stepper = (MauiStepper)d;
stepper.UpdateEnabled((double)e.NewValue);

stepper.ValueChanged?.Invoke(d, EventArgs.Empty);
}

VisualStateCache PseudoDisable(Control control)
{
if (VisualTreeHelper.GetChildrenCount(control) == 0)
Expand Down