Mercurial > silverbladetech
comparison MetroWpf/MetroWpf.Xaml/Controls/WatermarkTextBox.cs @ 18:8049f7c58c2b
Login form 75% there
author | stevenh7776 stevenhollidge@hotmail.com |
---|---|
date | Wed, 14 Mar 2012 18:06:36 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:7721a1270363 | 18:8049f7c58c2b |
---|---|
1 using System; | |
2 using System.Windows; | |
3 using System.Windows.Controls; | |
4 using System.Windows.Input; | |
5 | |
6 namespace Microsoft.Windows.Controls | |
7 { | |
8 public class WatermarkTextBox : TextBox | |
9 { | |
10 #region Properties | |
11 | |
12 #region SelectAllOnGotFocus | |
13 | |
14 public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(WatermarkTextBox), new PropertyMetadata(false)); | |
15 public bool SelectAllOnGotFocus | |
16 { | |
17 get { return (bool)GetValue(SelectAllOnGotFocusProperty); } | |
18 set { SetValue(SelectAllOnGotFocusProperty, value); } | |
19 } | |
20 | |
21 #endregion //SelectAllOnGotFocus | |
22 | |
23 #region Watermark | |
24 | |
25 public static readonly DependencyProperty WatermarkProperty = DependencyProperty.Register("Watermark", typeof(object), typeof(WatermarkTextBox), new UIPropertyMetadata(null)); | |
26 public object Watermark | |
27 { | |
28 get { return (object)GetValue(WatermarkProperty); } | |
29 set { SetValue(WatermarkProperty, value); } | |
30 } | |
31 | |
32 #endregion //Watermark | |
33 | |
34 #region WatermarkTemplate | |
35 | |
36 public static readonly DependencyProperty WatermarkTemplateProperty = DependencyProperty.Register("WatermarkTemplate", typeof(DataTemplate), typeof(WatermarkTextBox), new UIPropertyMetadata(null)); | |
37 public DataTemplate WatermarkTemplate | |
38 { | |
39 get { return (DataTemplate)GetValue(WatermarkTemplateProperty); } | |
40 set { SetValue(WatermarkTemplateProperty, value); } | |
41 } | |
42 | |
43 #endregion //WatermarkTemplate | |
44 | |
45 #endregion //Properties | |
46 | |
47 #region Constructors | |
48 | |
49 static WatermarkTextBox() | |
50 { | |
51 DefaultStyleKeyProperty.OverrideMetadata(typeof(WatermarkTextBox), new FrameworkPropertyMetadata(typeof(WatermarkTextBox))); | |
52 } | |
53 | |
54 #endregion //Constructors | |
55 | |
56 #region Base Class Overrides | |
57 | |
58 protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) | |
59 { | |
60 if (SelectAllOnGotFocus) | |
61 SelectAll(); | |
62 | |
63 base.OnGotKeyboardFocus(e); | |
64 } | |
65 | |
66 protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) | |
67 { | |
68 if (!IsKeyboardFocused) | |
69 { | |
70 e.Handled = true; | |
71 Focus(); | |
72 } | |
73 | |
74 base.OnPreviewMouseLeftButtonDown(e); | |
75 } | |
76 | |
77 #endregion //Base Class Overrides | |
78 } | |
79 } |