Skip to content
Merged
Show file tree
Hide file tree
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
113 changes: 113 additions & 0 deletions MaterialDesignThemes.Wpf.Tests/ButtonProgressAssistTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System.Windows.Controls;
using System.Windows.Media;
using Xunit;

namespace MaterialDesignThemes.Wpf.Tests
{
public class ButtonProgressAssistTests
{
private readonly Button _testElement;

public ButtonProgressAssistTests()
{
_testElement = new Button();
}

[Fact]
public void TestMinimumProperty()
{
// Assert defaults
Assert.Equal("Minimum", ButtonProgressAssist.MinimumProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetMinimum(_testElement));

// Assert setting works
ButtonProgressAssist.SetMinimum(_testElement, 133.14);
Assert.Equal(133.14, ButtonProgressAssist.GetMinimum(_testElement));
}

[Fact]
public void TestMaximumProperty()
{
// Assert defaults
Assert.Equal("Maximum", ButtonProgressAssist.MaximumProperty.Name);
Assert.Equal(100.0, ButtonProgressAssist.GetMaximum(_testElement));

// Assert setting works
ButtonProgressAssist.SetMaximum(_testElement, 39.56);
Assert.Equal(39.56, ButtonProgressAssist.GetMaximum(_testElement));
}

[Fact]
public void TestValueProperty()
{
// Assert defaults
Assert.Equal("Value", ButtonProgressAssist.ValueProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetValue(_testElement));

// Assert setting works
ButtonProgressAssist.SetValue(_testElement, 99.1);
Assert.Equal(99.1, ButtonProgressAssist.GetValue(_testElement));
}

[Fact]
public void TestIsIndeterminateProperty()
{
// Assert defaults
Assert.Equal("IsIndeterminate", ButtonProgressAssist.IsIndeterminateProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetIsIndeterminate(_testElement));

// Assert setting works
ButtonProgressAssist.SetIsIndeterminate(_testElement, false);
Assert.False(ButtonProgressAssist.GetIsIndeterminate(_testElement));
}

[Fact]
public void TestIndicatorForegroundProperty()
{
// Assert defaults
Assert.Equal("IndicatorForeground", ButtonProgressAssist.IndicatorForegroundProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetIndicatorForeground(_testElement));

// Assert setting works
ButtonProgressAssist.SetIndicatorForeground(_testElement, Brushes.LightBlue);
Assert.Equal(Brushes.LightBlue, ButtonProgressAssist.GetIndicatorForeground(_testElement));
}

[Fact]
public void TestIndicatorBackgroundProperty()
{
// Assert defaults
Assert.Equal("IndicatorBackground", ButtonProgressAssist.IndicatorBackgroundProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetIndicatorBackground(_testElement));

// Assert setting works
ButtonProgressAssist.SetIndicatorBackground(_testElement, Brushes.DarkGoldenrod);
Assert.Equal(Brushes.DarkGoldenrod, ButtonProgressAssist.GetIndicatorBackground(_testElement));
}

[Fact]
public void TestIsIndicatorVisibleProperty()
{
// Assert defaults
Assert.Equal("IsIndicatorVisible", ButtonProgressAssist.IsIndicatorVisibleProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetIsIndicatorVisible(_testElement));

// Assert setting works
ButtonProgressAssist.SetIsIndicatorVisible(_testElement, true);
Assert.True(ButtonProgressAssist.GetIsIndicatorVisible(_testElement));
}

[Fact]
public void TestOpacityProperty()
{
// Assert defaults
Assert.Equal("Opacity", ButtonProgressAssist.OpacityProperty.Name);
Assert.Equal(default, ButtonProgressAssist.GetOpacity(_testElement));

// Assert setting works
ButtonProgressAssist.SetOpacity(_testElement, 311);
Assert.Equal(311, ButtonProgressAssist.GetOpacity(_testElement));
}

}
}
171 changes: 67 additions & 104 deletions MaterialDesignThemes.Wpf/ButtonProgressAssist.cs
Original file line number Diff line number Diff line change
@@ -1,112 +1,75 @@
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf
{
public static class ButtonProgressAssist
{
public static readonly DependencyProperty MinimumProperty = DependencyProperty.RegisterAttached(
"Minimum", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static void SetMinimum(DependencyObject element, double value)
{
element.SetValue(MinimumProperty, value);
}

public static double GetMinimum(DependencyObject element)
{
return (double)element.GetValue(MinimumProperty);
}

public static readonly DependencyProperty MaximumProperty = DependencyProperty.RegisterAttached(
"Maximum", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(100.0));

public static void SetMaximum(DependencyObject element, double value)
{
element.SetValue(MaximumProperty, value);
}

public static double GetMaximum(DependencyObject element)
{
return (double)element.GetValue(MaximumProperty);
}

public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
"Value", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static void SetValue(DependencyObject element, double value)
{
element.SetValue(ValueProperty, value);
}

public static double GetValue(DependencyObject element)
{
return (double)element.GetValue(ValueProperty);
}

public static readonly DependencyProperty IsIndeterminateProperty = DependencyProperty.RegisterAttached(
"IsIndeterminate", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));

public static void SetIsIndeterminate(DependencyObject element, bool isIndeterminate)
{
element.SetValue(IsIndeterminateProperty, isIndeterminate);
}

public static bool GetIsIndeterminate(DependencyObject element)
{
return (bool)element.GetValue(IsIndeterminateProperty);
}

public static readonly DependencyProperty IndicatorForegroundProperty = DependencyProperty.RegisterAttached(
"IndicatorForeground", typeof(Brush), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(Brush)));

public static void SetIndicatorForeground(DependencyObject element, Brush indicatorForeground)
{
element.SetValue(IndicatorForegroundProperty, indicatorForeground);
}

public static Brush GetIndicatorForeground(DependencyObject element)
{
return (Brush)element.GetValue(IndicatorForegroundProperty);
}

public static readonly DependencyProperty IndicatorBackgroundProperty = DependencyProperty.RegisterAttached(
"IndicatorBackground", typeof(Brush), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(Brush)));

public static void SetIndicatorBackground(DependencyObject element, Brush indicatorBackground)
{
element.SetValue(IndicatorBackgroundProperty, indicatorBackground);
}

public static Brush GetIndicatorBackground(DependencyObject element)
{
return (Brush)element.GetValue(IndicatorBackgroundProperty);
}

public static readonly DependencyProperty IsIndicatorVisibleProperty = DependencyProperty.RegisterAttached(
"IsIndicatorVisible", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));

public static void SetIsIndicatorVisible(DependencyObject element, bool isIndicatorVisible)
{
element.SetValue(IsIndicatorVisibleProperty, isIndicatorVisible);
}

public static bool GetIsIndicatorVisible(DependencyObject element)
{
return (bool)element.GetValue(IsIndicatorVisibleProperty);
}

public static readonly DependencyProperty OpacityProperty = DependencyProperty.RegisterAttached(
"Opacity", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static void SetOpacity(DependencyObject element, double opacity)
{
element.SetValue(OpacityProperty, opacity);
}

public static double GetOpacity(DependencyObject element)
{
return (double)element.GetValue(OpacityProperty);
}
private const double DefaultMaximum = 100.0;

#region AttachedProperty : MinimumProperty
public static readonly DependencyProperty MinimumProperty
= DependencyProperty.RegisterAttached("Minimum", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static double GetMinimum(ButtonBase element) => (double)element.GetValue(MinimumProperty);
public static void SetMinimum(ButtonBase element, double value) => element.SetValue(MinimumProperty, value);
#endregion

#region AttachedProperty : MaximumProperty
public static readonly DependencyProperty MaximumProperty
= DependencyProperty.RegisterAttached("Maximum", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(DefaultMaximum));

public static double GetMaximum(ButtonBase element) => (double)element.GetValue(MaximumProperty);
public static void SetMaximum(ButtonBase element, double value) => element.SetValue(MaximumProperty, value);
#endregion

#region AttachedProperty : ValueProperty
public static readonly DependencyProperty ValueProperty
= DependencyProperty.RegisterAttached("Value", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static double GetValue(ButtonBase element) => (double)element.GetValue(ValueProperty);
public static void SetValue(ButtonBase element, double value) => element.SetValue(ValueProperty, value);
#endregion

#region AttachedProperty : IsIndeterminate
public static readonly DependencyProperty IsIndeterminateProperty
= DependencyProperty.RegisterAttached("IsIndeterminate", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));

public static bool GetIsIndeterminate(ButtonBase element) => (bool)element.GetValue(IsIndeterminateProperty);
public static void SetIsIndeterminate(ButtonBase element, bool isIndeterminate) => element.SetValue(IsIndeterminateProperty, isIndeterminate);
#endregion

#region AttachedProperty : IndicatorForegroundProperty
public static readonly DependencyProperty IndicatorForegroundProperty
= DependencyProperty.RegisterAttached("IndicatorForeground", typeof(Brush), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(Brush)));

public static Brush GetIndicatorForeground(ButtonBase element) => (Brush)element.GetValue(IndicatorForegroundProperty);
public static void SetIndicatorForeground(ButtonBase element, Brush indicatorForeground) => element.SetValue(IndicatorForegroundProperty, indicatorForeground);
#endregion

#region AttachedProperty : IndicatorBackgroundProperty
public static readonly DependencyProperty IndicatorBackgroundProperty
= DependencyProperty.RegisterAttached("IndicatorBackground", typeof(Brush), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(Brush)));

public static Brush GetIndicatorBackground(ButtonBase element) => (Brush)element.GetValue(IndicatorBackgroundProperty);
public static void SetIndicatorBackground(ButtonBase element, Brush indicatorBackground) => element.SetValue(IndicatorBackgroundProperty, indicatorBackground);
#endregion

#region AttachedProperty : IsIndicatorVisibleProperty
public static readonly DependencyProperty IsIndicatorVisibleProperty
= DependencyProperty.RegisterAttached("IsIndicatorVisible", typeof(bool), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(bool)));

public static bool GetIsIndicatorVisible(ButtonBase element) => (bool)element.GetValue(IsIndicatorVisibleProperty);
public static void SetIsIndicatorVisible(ButtonBase element, bool isIndicatorVisible) => element.SetValue(IsIndicatorVisibleProperty, isIndicatorVisible);
#endregion

#region AttachedProperty : OpacityProperty
public static readonly DependencyProperty OpacityProperty
= DependencyProperty.RegisterAttached("Opacity", typeof(double), typeof(ButtonProgressAssist), new FrameworkPropertyMetadata(default(double)));

public static double GetOpacity(ButtonBase element) => (double)element.GetValue(OpacityProperty);
public static void SetOpacity(ButtonBase element, double opacity) => element.SetValue(OpacityProperty, opacity);
#endregion
}
}
}