2 using System
.Collections
.Generic
;
5 using System
.Windows
.Controls
;
6 using System
.Windows
.Data
;
7 using System
.Windows
.Documents
;
8 using System
.Windows
.Input
;
9 using System
.Windows
.Media
;
10 using System
.Windows
.Media
.Imaging
;
11 using System
.Windows
.Navigation
;
12 using System
.Windows
.Shapes
;
14 namespace PopupPlacement
17 /// Interaction logic for NumericUpDownControl.xaml
20 public partial class NumericUpDownControl
: System
.Windows
.Controls
.UserControl
23 /// Initializes a new instance of the NumericUpDownControl.
25 public NumericUpDownControl()
27 InitializeComponent();
33 /// Identifies the DecreaseButtonContent property.
35 public static readonly DependencyProperty DecreaseButtonContentProperty
=
36 DependencyProperty
.Register("DecreaseButtonContent", typeof(object),
37 typeof(NumericUpDownControl
),
38 new PropertyMetadata(new PropertyChangedCallback(OnDecreaseTextChanged
)));
41 private static void OnDecreaseTextChanged(DependencyObject obj
, DependencyPropertyChangedEventArgs args
)
43 NumericUpDownControl control
= (NumericUpDownControl
)obj
;
44 control
.downButton
.Content
= args
.NewValue
;
50 /// Gets or sets the content in the Button that
53 public object DecreaseButtonContent
55 get { return GetValue(DecreaseButtonContentProperty); }
56 set { SetValue(DecreaseButtonContentProperty, value); }
61 ////////////////////////////////////////////////////////////////
63 /// Identifies the IncreaseButtonContent property.
65 public static readonly DependencyProperty IncreaseButtonContentProperty
=
66 DependencyProperty
.Register("IncreaseButtonContent", typeof(object),
67 typeof(NumericUpDownControl
),
68 new PropertyMetadata(new PropertyChangedCallback(OnIncreaseTextChanged
)));
71 private static void OnIncreaseTextChanged(DependencyObject obj
, DependencyPropertyChangedEventArgs args
)
73 NumericUpDownControl control
= (NumericUpDownControl
)obj
;
74 control
.upButton
.Content
= args
.NewValue
;
80 /// Gets or sets the content in the Button that
83 public object IncreaseButtonContent
85 get { return GetValue(IncreaseButtonContentProperty); }
86 set {SetValue(IncreaseButtonContentProperty, value);}
91 /// Gets or sets the value assigned to the control.
95 get { return (decimal)GetValue(ValueProperty); }
96 set { SetValue(ValueProperty, value); }
100 /// Identifies the Value dependency property.
102 public static readonly DependencyProperty ValueProperty
=
103 DependencyProperty
.Register(
104 "Value", typeof(decimal), typeof(NumericUpDownControl
),
105 new FrameworkPropertyMetadata(new PropertyChangedCallback(OnValueChanged
)));
107 private static void OnValueChanged(DependencyObject obj
, DependencyPropertyChangedEventArgs args
)
109 NumericUpDownControl control
= (NumericUpDownControl
)obj
;
110 control
.UpdateTextBlock();
112 RoutedPropertyChangedEventArgs
<decimal> e
= new RoutedPropertyChangedEventArgs
<decimal>(
113 (decimal)args
.OldValue
, (decimal)args
.NewValue
, ValueChangedEvent
);
114 control
.OnValueChanged(e
);
118 /// Identifies the ValueChanged routed event.
120 public static readonly RoutedEvent ValueChangedEvent
= EventManager
.RegisterRoutedEvent(
121 "ValueChanged", RoutingStrategy
.Bubble
,
122 typeof(RoutedPropertyChangedEventHandler
<decimal>), typeof(NumericUpDownControl
));
125 /// Occurs when the Value property changes.
127 public event RoutedPropertyChangedEventHandler
<decimal> ValueChanged
129 add { AddHandler(ValueChangedEvent, value); }
130 remove { RemoveHandler(ValueChangedEvent, value); }
134 /// Raises the ValueChanged event.
136 /// <param name="args">Arguments associated with the ValueChanged event.</param>
137 protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs
<decimal> args
)
142 private void upButton_Click(object sender
, EventArgs e
)
147 private void downButton_Click(object sender
, EventArgs e
)
152 private void UpdateTextBlock()
154 valueText
.Text
= Value
.ToString();