|
| 1 | +using MahApps.Metro.Converters; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.ComponentModel; |
| 5 | +using System.Linq; |
| 6 | +using System.Text; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using System.Windows; |
| 9 | +using System.Windows.Controls; |
| 10 | +using System.Windows.Data; |
| 11 | +using System.Windows.Documents; |
| 12 | +using System.Windows.Input; |
| 13 | +using System.Windows.Media; |
| 14 | +using System.Windows.Media.Animation; |
| 15 | +using System.Windows.Media.Imaging; |
| 16 | +using System.Windows.Navigation; |
| 17 | +using System.Windows.Shapes; |
| 18 | + |
| 19 | +namespace OATControl.Controls |
| 20 | +{ |
| 21 | + /// <summary> |
| 22 | + /// Interaction logic for PushButton.xaml |
| 23 | + /// </summary> |
| 24 | + public partial class PushButton : UserControl |
| 25 | + { |
| 26 | + /// <summary> |
| 27 | + /// The dependency property for the Minimum property |
| 28 | + /// </summary> |
| 29 | + |
| 30 | + public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register( |
| 31 | + "Direction", |
| 32 | + typeof(char), |
| 33 | + typeof(PushButton), |
| 34 | + new PropertyMetadata('A', PushButton.DirectionPropertyChanged)); |
| 35 | + |
| 36 | + public static readonly DependencyProperty IsPressedProperty = DependencyProperty.Register( |
| 37 | + "IsPressed", |
| 38 | + typeof(bool), |
| 39 | + typeof(PushButton), |
| 40 | + new PropertyMetadata(false, PushButton.AnyPropertyChanged)); |
| 41 | + |
| 42 | + public static readonly DependencyProperty RotAngleProperty = DependencyProperty.Register( |
| 43 | + "RotAngle", |
| 44 | + typeof(double), |
| 45 | + typeof(PushButton), |
| 46 | + new PropertyMetadata(0.0, PushButton.AnyPropertyChanged)); |
| 47 | + |
| 48 | + public static readonly DependencyProperty CommandProperty = DependencyProperty.Register( |
| 49 | + "Command", |
| 50 | + typeof(ICommand), |
| 51 | + typeof(PushButton), |
| 52 | + new PropertyMetadata(null, PushButton.AnyPropertyChanged)); |
| 53 | + |
| 54 | + public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register( |
| 55 | + "CommandParameter", |
| 56 | + typeof(object), |
| 57 | + typeof(PushButton), |
| 58 | + new PropertyMetadata(null, PushButton.AnyPropertyChanged)); |
| 59 | + |
| 60 | + // |
| 61 | + // Summary: |
| 62 | + // Gets or sets the parameter to pass to the System.Windows.Controls.Primitives.ButtonBase.Command |
| 63 | + // property. |
| 64 | + // |
| 65 | + // Returns: |
| 66 | + // Parameter to pass to the System.Windows.Controls.Primitives.ButtonBase.Command |
| 67 | + // property. |
| 68 | + [Bindable(true)] |
| 69 | + [Category("Action")] |
| 70 | + [Localizability(LocalizationCategory.NeverLocalize)] |
| 71 | + public object CommandParameter |
| 72 | + { |
| 73 | + get |
| 74 | + { |
| 75 | + return this.GetValue(PushButton.CommandParameterProperty); |
| 76 | + } |
| 77 | + set |
| 78 | + { |
| 79 | + this.SetValue(PushButton.CommandParameterProperty, value); |
| 80 | + } |
| 81 | + } |
| 82 | + // |
| 83 | + // Summary: |
| 84 | + // Gets or sets the command to invoke when this button is pressed. |
| 85 | + // |
| 86 | + // Returns: |
| 87 | + // A command to invoke when this button is pressed. The default value is null. |
| 88 | + [Bindable(true)] |
| 89 | + [Category("Action")] |
| 90 | + [Localizability(LocalizationCategory.NeverLocalize)] |
| 91 | + public ICommand Command |
| 92 | + { |
| 93 | + get |
| 94 | + { |
| 95 | + return (ICommand)this.GetValue(PushButton.CommandProperty); |
| 96 | + } |
| 97 | + set |
| 98 | + { |
| 99 | + this.SetValue(PushButton.CommandProperty, value); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private static void DirectionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) |
| 104 | + { |
| 105 | + var pushButton = obj as PushButton; |
| 106 | + switch (char.ToUpper((char)e.NewValue)) |
| 107 | + { |
| 108 | + case 'N': pushButton.RotAngle = 270.0;break; |
| 109 | + case 'E': pushButton.RotAngle = 0.0; break; |
| 110 | + case 'W': pushButton.RotAngle = 180.0; break; |
| 111 | + case 'S': pushButton.RotAngle = 90.0; break; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + private static void AnyPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) |
| 116 | + { |
| 117 | + var pushButton = obj as PushButton; |
| 118 | + } |
| 119 | + |
| 120 | + public PushButton() |
| 121 | + { |
| 122 | + InitializeComponent(); |
| 123 | + //this.DataContext = this; |
| 124 | + } |
| 125 | + |
| 126 | + [Bindable(true)] |
| 127 | + public char Direction |
| 128 | + { |
| 129 | + get |
| 130 | + { |
| 131 | + return (char)this.GetValue(PushButton.DirectionProperty); |
| 132 | + } |
| 133 | + set |
| 134 | + { |
| 135 | + this.SetValue(PushButton.DirectionProperty, value); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + [Bindable(true)] |
| 140 | + public double RotAngle |
| 141 | + { |
| 142 | + get |
| 143 | + { |
| 144 | + return (double)this.GetValue(PushButton.RotAngleProperty); |
| 145 | + } |
| 146 | + set |
| 147 | + { |
| 148 | + this.SetValue(PushButton.RotAngleProperty, value); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + [Bindable(true)] |
| 153 | + public bool IsPressed |
| 154 | + { |
| 155 | + get |
| 156 | + { |
| 157 | + return (bool)this.GetValue(PushButton.IsPressedProperty); |
| 158 | + } |
| 159 | + set |
| 160 | + { |
| 161 | + this.SetValue(PushButton.IsPressedProperty, value); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + |
| 166 | + /// <summary> |
| 167 | + /// Handles the OnMouseButtonDown event of the MainGrid control. Captures the mouse and sets the current |
| 168 | + /// value to the click point. If the textbox currently is active, it is made inactive. |
| 169 | + /// </summary> |
| 170 | + /// <param name="sender">The source of the event.</param> |
| 171 | + /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param> |
| 172 | + private void MainGrid_OnMouseButtonDown(object sender, MouseButtonEventArgs e) |
| 173 | + { |
| 174 | + if (e.LeftButton == MouseButtonState.Pressed) |
| 175 | + { |
| 176 | + IsPressed = true; |
| 177 | + this.MainGrid.CaptureMouse(); |
| 178 | + this.Command.Execute("+" + CommandParameter.ToString()); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + /// <summary> |
| 183 | + /// Handles the OnMouseButtonUp event of the MainGrid control. |
| 184 | + /// </summary> |
| 185 | + /// <param name="sender">The source of the event.</param> |
| 186 | + /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param> |
| 187 | + private void MainGrid_OnMouseButtonUp(object sender, MouseButtonEventArgs e) |
| 188 | + { |
| 189 | + this.MainGrid.ReleaseMouseCapture(); |
| 190 | + IsPressed = false; |
| 191 | + this.Command.Execute("-" + CommandParameter.ToString()); |
| 192 | + } |
| 193 | + } |
| 194 | +} |
0 commit comments