Browse Source

ButtonSpinner: Added AllowSpin and ShowButtonSpinner properties

UpDownBase: Added AllowSpin and ShowButtonSpinner properties
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
70f5b84375
  1. 118
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Implementation/ButtonSpinner.cs
  2. 4
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Themes/Generic.xaml
  3. 37
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/UpDownBase.cs
  4. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Themes/Generic.xaml
  5. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml

118
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Implementation/ButtonSpinner.cs

@ -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
}
}

4
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Themes/Generic.xaml

@ -7,6 +7,8 @@
<!-- ButtonSpinner -->
<!-- =============================================================================== -->
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<SolidColorBrush x:Key="SpinButtonGlyphNormalForegroundFillKey" Color="#FF000000" />
<DataTemplate x:Key="IncreaseGlyph">
@ -40,7 +42,7 @@
<Grid>
<Border x:Name="ElementContainer" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<DockPanel Focusable="False">
<Grid DockPanel.Dock="Right">
<Grid DockPanel.Dock="Right" Visibility="{TemplateBinding ShowButtonSpinner, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1" />

37
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/UpDownBase.cs

@ -2,6 +2,7 @@
using System.Windows.Controls;
using Microsoft.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows;
namespace Microsoft.Windows.Controls.Primitives
{
@ -23,6 +24,28 @@ namespace Microsoft.Windows.Controls.Primitives
#region Properties
#region AllowSpin
public static readonly DependencyProperty AllowSpinProperty = DependencyProperty.Register("AllowSpin", typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(true));
public bool AllowSpin
{
get { return (bool)GetValue(AllowSpinProperty); }
set { SetValue(AllowSpinProperty, value); }
}
#endregion //AllowSpin
#region ShowButtonSpinner
public static readonly DependencyProperty ShowButtonSpinnerProperty = DependencyProperty.Register("ShowButtonSpinner", typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(true));
public bool ShowButtonSpinner
{
get { return (bool)GetValue(ShowButtonSpinnerProperty); }
set { SetValue(ShowButtonSpinnerProperty, value); }
}
#endregion //ShowButtonSpinner
protected TextBox TextBox { get; private set; }
private Spinner _spinner;
@ -60,19 +83,22 @@ namespace Microsoft.Windows.Controls.Primitives
{
case Key.Up:
{
DoIncrement();
if (AllowSpin)
DoIncrement();
e.Handled = true;
break;
}
case Key.Down:
{
DoDecrement();
if (AllowSpin)
DoDecrement();
e.Handled = true;
break;
}
case Key.Enter:
{
SyncTextAndValueProperties(UpDownBase.TextProperty, TextBox.Text);
if (IsEditable)
SyncTextAndValueProperties(UpDownBase.TextProperty, TextBox.Text);
break;
}
}
@ -82,7 +108,7 @@ namespace Microsoft.Windows.Controls.Primitives
{
base.OnMouseWheel(e);
if (!e.Handled)
if (!e.Handled && AllowSpin)
{
if (e.Delta < 0)
{
@ -103,7 +129,8 @@ namespace Microsoft.Windows.Controls.Primitives
private void OnSpinnerSpin(object sender, SpinEventArgs e)
{
OnSpin(e);
if (AllowSpin)
OnSpin(e);
}
#endregion //Event Handlers

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Themes/Generic.xaml

@ -8,12 +8,13 @@
<Style TargetType="{x:Type local:DateTimeUpDown}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Focusable" Value="False" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:DateTimeUpDown}">
<local:ButtonSpinner x:Name="Spinner" IsTabStop="False" BorderThickness="{TemplateBinding BorderThickness}">
<local:ButtonSpinner x:Name="Spinner" IsTabStop="False" BorderThickness="{TemplateBinding BorderThickness}"
AllowSpin="{TemplateBinding AllowSpin}" ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
<TextBox x:Name="TextBox" BorderThickness="0"
Background="{TemplateBinding Background}"
FontFamily="{TemplateBinding FontFamily}"

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml

@ -10,11 +10,14 @@
<!-- =============================================================================== -->
<Style TargetType="{x:Type local:NumericUpDown}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NumericUpDown}">
<local:ButtonSpinner x:Name="Spinner" IsTabStop="False">
<local:ButtonSpinner x:Name="Spinner" IsTabStop="False" BorderThickness="{TemplateBinding BorderThickness}"
AllowSpin="{TemplateBinding AllowSpin}" ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
<TextBox x:Name="TextBox" BorderThickness="0"
Background="{TemplateBinding Background}"
FontFamily="{TemplateBinding FontFamily}"

Loading…
Cancel
Save