summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Componentes/CustomSenhaLoginBox.cs
blob: ce1a27846abef6dbe0b5260dea7eb8ac0cdac9ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using ControlzEx;
using MaterialDesignThemes.Wpf;
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media;

namespace Gestor.Application.Componentes
{
	public class CustomSenhaLoginBox : UserControl, IComponentConnector
	{
		public readonly static DependencyProperty TextProperty;

		public readonly static DependencyProperty IsReadOnlyProperty;

		public readonly static DependencyProperty PlaceHolderProperty;

		public readonly static DependencyProperty BackgroundProperty;

		public readonly static DependencyProperty ForegroundProperty;

		public readonly static DependencyProperty CaretBrushProperty;

		public readonly static DependencyProperty FontFamilyProperty;

		public readonly static DependencyProperty FontSizeProperty;

		public readonly static DependencyProperty BorderThicknessProperty;

		internal Grid LayoutRoot;

		internal TextBox TextRead;

		internal System.Windows.Controls.PasswordBox PasswordBox;

		internal Button ButtonEye;

		private bool _contentLoaded;

		private static bool _typing
		{
			get;
			set;
		}

		public new Brush Background
		{
			get
			{
				return (Brush)base.GetValue(CustomSenhaLoginBox.BackgroundProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.BackgroundProperty, value);
			}
		}

		public new Thickness BorderThickness
		{
			get
			{
				return (Thickness)base.GetValue(CustomSenhaLoginBox.BorderThicknessProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.BorderThicknessProperty, value);
			}
		}

		public Brush CaretBrush
		{
			get
			{
				return (Brush)base.GetValue(CustomSenhaLoginBox.CaretBrushProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.CaretBrushProperty, value);
			}
		}

		public new System.Windows.Media.FontFamily FontFamily
		{
			get
			{
				return (System.Windows.Media.FontFamily)base.GetValue(CustomSenhaLoginBox.FontFamilyProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.FontFamilyProperty, value);
			}
		}

		public new int FontSize
		{
			get
			{
				return (int)base.GetValue(CustomSenhaLoginBox.FontSizeProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.FontSizeProperty, value);
			}
		}

		public new Brush Foreground
		{
			get
			{
				return (Brush)base.GetValue(CustomSenhaLoginBox.ForegroundProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.ForegroundProperty, value);
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return (bool)base.GetValue(CustomSenhaLoginBox.IsReadOnlyProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.IsReadOnlyProperty, value);
			}
		}

		public string PlaceHolder
		{
			get
			{
				return (string)base.GetValue(CustomSenhaLoginBox.PlaceHolderProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.PlaceHolderProperty, value);
			}
		}

		public string Text
		{
			get
			{
				return (string)base.GetValue(CustomSenhaLoginBox.TextProperty);
			}
			set
			{
				base.SetValue(CustomSenhaLoginBox.TextProperty, value);
			}
		}

		static CustomSenhaLoginBox()
		{
			CustomSenhaLoginBox.TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CustomSenhaLoginBox), new PropertyMetadata(string.Empty, new PropertyChangedCallback(CustomSenhaLoginBox.OnBoundPasswordChanged)));
			CustomSenhaLoginBox.IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(CustomSenhaLoginBox), new PropertyMetadata(false, new PropertyChangedCallback(CustomSenhaLoginBox.OnBoundIsReadOnlyChanged)));
			CustomSenhaLoginBox.PlaceHolderProperty = DependencyProperty.Register("PlaceHolder", typeof(string), typeof(CustomSenhaLoginBox), new FrameworkPropertyMetadata("SENHA", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
			CustomSenhaLoginBox.BackgroundProperty = DependencyProperty.Register("Background", typeof(Brush), typeof(CustomSenhaLoginBox), new PropertyMetadata(null, new PropertyChangedCallback(CustomSenhaLoginBox.OnBackgroundChanged)));
			CustomSenhaLoginBox.ForegroundProperty = DependencyProperty.Register("Foreground", typeof(Brush), typeof(CustomSenhaLoginBox), new PropertyMetadata(null, new PropertyChangedCallback(CustomSenhaLoginBox.OnForegroundChanged)));
			CustomSenhaLoginBox.CaretBrushProperty = DependencyProperty.Register("CaretBrush", typeof(Brush), typeof(CustomSenhaLoginBox), new PropertyMetadata(null, new PropertyChangedCallback(CustomSenhaLoginBox.OnCaretBrushChanged)));
			CustomSenhaLoginBox.FontFamilyProperty = DependencyProperty.Register("FontFamily", typeof(System.Windows.Media.FontFamily), typeof(CustomSenhaLoginBox), new PropertyMetadata(null, new PropertyChangedCallback(CustomSenhaLoginBox.OnFontFamilyChanged)));
			CustomSenhaLoginBox.FontSizeProperty = DependencyProperty.Register("FontSize", typeof(int), typeof(CustomSenhaLoginBox), new PropertyMetadata((object)10, new PropertyChangedCallback(CustomSenhaLoginBox.OnFontSizeChanged)));
			CustomSenhaLoginBox.BorderThicknessProperty = DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(CustomSenhaLoginBox), new PropertyMetadata((object)(new Thickness(1)), new PropertyChangedCallback(CustomSenhaLoginBox.OnBorderThicknessChanged)));
		}

		public CustomSenhaLoginBox()
		{
			this.InitializeComponent();
			this.LayoutRoot.DataContext = this;
		}

		private void Eye_Click(object sender, RoutedEventArgs e)
		{
			if (this.IsReadOnly)
			{
				return;
			}
			Button button = sender as Button;
			this.TextRead.Visibility = (this.TextRead.Visibility == System.Windows.Visibility.Collapsed ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
			this.PasswordBox.Visibility = (this.TextRead.Visibility == System.Windows.Visibility.Collapsed ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
			if (button != null && button.Content != null)
			{
				((PackIcon)button.Content).set_Kind((this.TextRead.Visibility == System.Windows.Visibility.Collapsed ? 1492 : 1497));
			}
			if (this.PasswordBox.Visibility != System.Windows.Visibility.Visible)
			{
				return;
			}
			this.PasswordBox.Focus();
			this.PasswordBox.SelectAll();
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/componentes/customsenhaloginbox.xaml", UriKind.Relative));
		}

		private static void OnBackgroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.Background = (Brush)e.NewValue;
		}

		private static void OnBorderThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.BorderThickness = (Thickness)e.NewValue;
		}

		private static void OnBoundIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomPasswordBox customPasswordBox = d as CustomPasswordBox;
			if (d == null || customPasswordBox == null)
			{
				return;
			}
			bool newValue = (bool)e.NewValue;
			customPasswordBox.PasswordBox.Visibility = (newValue ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible);
			customPasswordBox.TextRead.Visibility = (newValue ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed);
		}

		private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox customSenhaLoginBox = d as CustomSenhaLoginBox;
			if (d == null || customSenhaLoginBox == null)
			{
				return;
			}
			string newValue = (string)e.NewValue ?? "";
			if (CustomSenhaLoginBox._typing)
			{
				return;
			}
			customSenhaLoginBox.PasswordBox.Password = newValue;
		}

		private static void OnCaretBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.CaretBrush = (Brush)e.NewValue;
		}

		private static void OnFontFamilyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.FontFamily = (System.Windows.Media.FontFamily)e.NewValue;
		}

		private static void OnFontSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.FontSize = (int)e.NewValue;
		}

		private static void OnForegroundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			CustomSenhaLoginBox newValue = d as CustomSenhaLoginBox;
			if (d == null || newValue == null)
			{
				return;
			}
			newValue.Foreground = (Brush)e.NewValue;
		}

		private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
		{
			CustomSenhaLoginBox._typing = true;
			this.Text = this.PasswordBox.Password;
			CustomSenhaLoginBox._typing = false;
		}

		[DebuggerNonUserCode]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
				case 1:
				{
					this.LayoutRoot = (Grid)target;
					return;
				}
				case 2:
				{
					this.TextRead = (TextBox)target;
					return;
				}
				case 3:
				{
					this.PasswordBox = (System.Windows.Controls.PasswordBox)target;
					this.PasswordBox.PasswordChanged += new RoutedEventHandler(this.PasswordBox_PasswordChanged);
					return;
				}
				case 4:
				{
					this.ButtonEye = (Button)target;
					this.ButtonEye.Click += new RoutedEventHandler(this.Eye_Click);
					return;
				}
			}
			this._contentLoaded = true;
		}
	}
}