added samples
[windows-sources.git] / sdk / samples / WPFSamples / PopupPlacement / csharp / numericupdowncontrol.xaml.cs
blobff566405a1917c4811e7af81a061b25bf6232286
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows;
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
16 /// <summary>
17 /// Interaction logic for NumericUpDownControl.xaml
18 /// </summary>
20 public partial class NumericUpDownControl : System.Windows.Controls.UserControl
22 /// <summary>
23 /// Initializes a new instance of the NumericUpDownControl.
24 /// </summary>
25 public NumericUpDownControl()
27 InitializeComponent();
29 UpdateTextBlock();
32 /// <summary>
33 /// Identifies the DecreaseButtonContent property.
34 /// </summary>
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;
49 /// <summary>
50 /// Gets or sets the content in the Button that
51 /// Decreases Value.
52 /// </summary>
53 public object DecreaseButtonContent
55 get { return GetValue(DecreaseButtonContentProperty); }
56 set { SetValue(DecreaseButtonContentProperty, value); }
61 ////////////////////////////////////////////////////////////////
62 /// <summary>
63 /// Identifies the IncreaseButtonContent property.
64 /// </summary>
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;
79 /// <summary>
80 /// Gets or sets the content in the Button that
81 /// increases Value.
82 /// </summary>
83 public object IncreaseButtonContent
85 get { return GetValue(IncreaseButtonContentProperty); }
86 set {SetValue(IncreaseButtonContentProperty, value);}
90 /// <summary>
91 /// Gets or sets the value assigned to the control.
92 /// </summary>
93 public decimal Value
95 get { return (decimal)GetValue(ValueProperty); }
96 set { SetValue(ValueProperty, value); }
99 /// <summary>
100 /// Identifies the Value dependency property.
101 /// </summary>
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);
117 /// <summary>
118 /// Identifies the ValueChanged routed event.
119 /// </summary>
120 public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent(
121 "ValueChanged", RoutingStrategy.Bubble,
122 typeof(RoutedPropertyChangedEventHandler<decimal>), typeof(NumericUpDownControl));
124 /// <summary>
125 /// Occurs when the Value property changes.
126 /// </summary>
127 public event RoutedPropertyChangedEventHandler<decimal> ValueChanged
129 add { AddHandler(ValueChangedEvent, value); }
130 remove { RemoveHandler(ValueChangedEvent, value); }
133 /// <summary>
134 /// Raises the ValueChanged event.
135 /// </summary>
136 /// <param name="args">Arguments associated with the ValueChanged event.</param>
137 protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs<decimal> args)
139 RaiseEvent(args);
142 private void upButton_Click(object sender, EventArgs e)
144 Value++;
147 private void downButton_Click(object sender, EventArgs e)
149 Value--;
152 private void UpdateTextBlock()
154 valueText.Text = Value.ToString();