|
|
|
@ -14,6 +14,17 @@ namespace Microsoft.Windows.Controls |
|
|
|
{ |
|
|
|
#region Properties
|
|
|
|
|
|
|
|
#region AllowSpin
|
|
|
|
|
|
|
|
public static readonly DependencyProperty AllowSpinProperty = DependencyProperty.Register("AllowSpin", typeof(bool), typeof(ButtonSpinner), new UIPropertyMetadata(true)); |
|
|
|
public bool AllowSpin |
|
|
|
{ |
|
|
|
get { return (bool)GetValue(AllowSpinProperty); } |
|
|
|
set { SetValue(AllowSpinProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //AllowSpin
|
|
|
|
|
|
|
|
#region Content
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -39,53 +50,71 @@ namespace Microsoft.Windows.Controls |
|
|
|
|
|
|
|
#endregion //Content
|
|
|
|
|
|
|
|
private ButtonBase _increaseButton; |
|
|
|
#region DecreaseButton
|
|
|
|
|
|
|
|
private ButtonBase _decreaseButton; |
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the IncreaseButton template part.
|
|
|
|
/// Gets or sets the DecreaseButton template part.
|
|
|
|
/// </summary>
|
|
|
|
private ButtonBase IncreaseButton |
|
|
|
private ButtonBase DecreaseButton |
|
|
|
{ |
|
|
|
get { return _increaseButton; } |
|
|
|
get { return _decreaseButton; } |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_increaseButton != null) |
|
|
|
if (_decreaseButton != null) |
|
|
|
{ |
|
|
|
_increaseButton.Click -= OnButtonClick; |
|
|
|
_decreaseButton.Click -= OnButtonClick; |
|
|
|
} |
|
|
|
|
|
|
|
_increaseButton = value; |
|
|
|
_decreaseButton = value; |
|
|
|
|
|
|
|
if (_increaseButton != null) |
|
|
|
if (_decreaseButton != null) |
|
|
|
{ |
|
|
|
_increaseButton.Click += OnButtonClick; |
|
|
|
_decreaseButton.Click += OnButtonClick; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //DecreaseButton
|
|
|
|
|
|
|
|
private ButtonBase _decreaseButton; |
|
|
|
#region IncreaseButton
|
|
|
|
|
|
|
|
private ButtonBase _increaseButton; |
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the DecreaseButton template part.
|
|
|
|
/// Gets or sets the IncreaseButton template part.
|
|
|
|
/// </summary>
|
|
|
|
private ButtonBase DecreaseButton |
|
|
|
private ButtonBase IncreaseButton |
|
|
|
{ |
|
|
|
get { return _decreaseButton; } |
|
|
|
get { return _increaseButton; } |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_decreaseButton != null) |
|
|
|
if (_increaseButton != null) |
|
|
|
{ |
|
|
|
_decreaseButton.Click -= OnButtonClick; |
|
|
|
_increaseButton.Click -= OnButtonClick; |
|
|
|
} |
|
|
|
|
|
|
|
_decreaseButton = value; |
|
|
|
_increaseButton = value; |
|
|
|
|
|
|
|
if (_decreaseButton != null) |
|
|
|
if (_increaseButton != null) |
|
|
|
{ |
|
|
|
_decreaseButton.Click += OnButtonClick; |
|
|
|
_increaseButton.Click += OnButtonClick; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //IncreaseButton
|
|
|
|
|
|
|
|
#region ShowButtonSpinner
|
|
|
|
|
|
|
|
public static readonly DependencyProperty ShowButtonSpinnerProperty = DependencyProperty.Register("ShowButtonSpinner", typeof(bool), typeof(ButtonSpinner), new UIPropertyMetadata(true)); |
|
|
|
public bool ShowButtonSpinner |
|
|
|
{ |
|
|
|
get { return (bool)GetValue(ShowButtonSpinnerProperty); } |
|
|
|
set { SetValue(ShowButtonSpinnerProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //ShowButtonSpinner
|
|
|
|
|
|
|
|
#endregion //Properties
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
@ -109,27 +138,6 @@ namespace Microsoft.Windows.Controls |
|
|
|
SetButtonUsage(); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //Base Class Overrides
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the Content property value changed.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="oldValue">The old value of the Content property.</param>
|
|
|
|
/// <param name="newValue">The new value of the Content property.</param>
|
|
|
|
protected virtual void OnContentChanged(object oldValue, object newValue) { } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handle click event of IncreaseButton and DecreaseButton template parts,
|
|
|
|
/// translating Click to appropriate Spin event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">Event sender, should be either IncreaseButton or DecreaseButton template part.</param>
|
|
|
|
/// <param name="e">Event args.</param>
|
|
|
|
private void OnButtonClick(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
SpinDirection direction = sender == IncreaseButton ? SpinDirection.Increase : SpinDirection.Decrease; |
|
|
|
OnSpin(new SpinEventArgs(direction)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Cancel LeftMouseButtonUp events originating from a button that has
|
|
|
|
/// been changed to disabled.
|
|
|
|
@ -171,6 +179,36 @@ namespace Microsoft.Windows.Controls |
|
|
|
SetButtonUsage(); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //Base Class Overrides
|
|
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handle click event of IncreaseButton and DecreaseButton template parts,
|
|
|
|
/// translating Click to appropriate Spin event.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">Event sender, should be either IncreaseButton or DecreaseButton template part.</param>
|
|
|
|
/// <param name="e">Event args.</param>
|
|
|
|
private void OnButtonClick(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
if (AllowSpin) |
|
|
|
{ |
|
|
|
SpinDirection direction = sender == IncreaseButton ? SpinDirection.Increase : SpinDirection.Decrease; |
|
|
|
OnSpin(new SpinEventArgs(direction)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //Event Handlers
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Occurs when the Content property value changed.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="oldValue">The old value of the Content property.</param>
|
|
|
|
/// <param name="newValue">The new value of the Content property.</param>
|
|
|
|
protected virtual void OnContentChanged(object oldValue, object newValue) { } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Disables or enables the buttons based on the valid spin direction.
|
|
|
|
/// </summary>
|
|
|
|
@ -187,5 +225,7 @@ namespace Microsoft.Windows.Controls |
|
|
|
DecreaseButton.IsEnabled = ((ValidSpinDirection & ValidSpinDirections.Decrease) == ValidSpinDirections.Decrease); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion //Methods
|
|
|
|
} |
|
|
|
} |
|
|
|
|