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