summaryrefslogtreecommitdiff
path: root/Gestor.Application/Componentes/PassBox.cs
blob: 9ca18aaa664eaa078428ac182748a03accec8258 (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
using Gestor.Common.Validation;
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.Input;
using System.Windows.Markup;

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

		public readonly static DependencyProperty HintProperty;

		public readonly static DependencyProperty PasswordWidthProperty;

		private bool _hidePasswordView;

		internal Grid LayoutRoot;

		internal Button ShowHidePassword;

		internal PasswordBox TextPassword;

		internal TextBox TextPasswordVisible;

		private bool _contentLoaded;

		public bool HidePasswordView
		{
			get
			{
				return this._hidePasswordView;
			}
			set
			{
				if (value)
				{
					this.HidePassword();
				}
			}
		}

		public string Hint
		{
			get
			{
				return (string)base.GetValue(PassBox.HintProperty);
			}
			set
			{
				base.SetValue(PassBox.HintProperty, value);
			}
		}

		public string PasswordWidth
		{
			get
			{
				return (string)base.GetValue(PassBox.PasswordWidthProperty);
			}
			set
			{
				base.SetValue(PassBox.PasswordWidthProperty, value);
			}
		}

		public string Value
		{
			get
			{
				return (string)base.GetValue(PassBox.ValueProperty);
			}
			set
			{
				base.SetValue(PassBox.ValueProperty, value);
			}
		}

		public bool Visible
		{
			get;
			set;
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}

		static PassBox()
		{
			PassBox.ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(PassBox), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
			PassBox.HintProperty = DependencyProperty.Register("Hint", typeof(string), typeof(PassBox), new FrameworkPropertyMetadata("SENHA", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
			PassBox.PasswordWidthProperty = DependencyProperty.Register("PasswordWidth", typeof(string), typeof(PassBox), new PropertyMetadata(null, new PropertyChangedCallback(PassBox.OnBoundWidthChanged)));
		}

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

		public void HidePassword()
		{
			this.TextPasswordVisible.Visibility = System.Windows.Visibility.Hidden;
			this.TextPassword.Visibility = System.Windows.Visibility.Visible;
			this.TextPassword.Focus();
			this.Visible = false;
		}

		[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/passbox.xaml", UriKind.Relative));
		}

		private static void OnBoundWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			PassBox passBox = d as PassBox;
			if (d == null || passBox == null)
			{
				return;
			}
			string newValue = (string)e.NewValue;
			if (!ValidationHelper.ValidateDouble(newValue))
			{
				return;
			}
			passBox.TextPassword.MinWidth = double.Parse(newValue);
			passBox.TextPasswordVisible.MinWidth = double.Parse(newValue);
		}

		private void ShowHidePassword_OnClick(object sender, RoutedEventArgs e)
		{
			if (this.Visible)
			{
				this.HidePassword();
				return;
			}
			this.ShowPassword();
		}

		private void ShowHidePassword_OnMouseDown(object sender, MouseButtonEventArgs e)
		{
			this.ShowPassword();
		}

		private void ShowHidePassword_OnMouseUp(object sender, MouseButtonEventArgs e)
		{
			this.HidePassword();
		}

		public void ShowPassword()
		{
			this.TextPasswordVisible.Visibility = System.Windows.Visibility.Visible;
			this.TextPassword.Visibility = System.Windows.Visibility.Hidden;
			this.TextPasswordVisible.Focus();
			this.Visible = true;
		}

		[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.ShowHidePassword = (Button)target;
					this.ShowHidePassword.PreviewMouseDown += new MouseButtonEventHandler(this.ShowHidePassword_OnMouseDown);
					this.ShowHidePassword.PreviewMouseUp += new MouseButtonEventHandler(this.ShowHidePassword_OnMouseUp);
					return;
				}
				case 3:
				{
					this.TextPassword = (PasswordBox)target;
					this.TextPassword.PasswordChanged += new RoutedEventHandler(this.TextPassword_PasswordChanged);
					return;
				}
				case 4:
				{
					this.TextPasswordVisible = (TextBox)target;
					return;
				}
			}
			this._contentLoaded = true;
		}

		private void TextPassword_PasswordChanged(object sender, RoutedEventArgs e)
		{
		}
	}
}