diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-03-03 23:05:27 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-03-03 23:05:27 +0200 |
| commit | 9dedf143c3ac44ca593e735861f4e1e2e6f947c9 (patch) | |
| tree | 24e74858582300add1f165d4515d9ee8e4a609c5 /Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs | |
| parent | 96efb4716d16ab7dab67ead42f27b871b81d4111 (diff) | |
| download | Tango-9dedf143c3ac44ca593e735861f4e1e2e6f947c9.tar.gz Tango-9dedf143c3ac44ca593e735861f4e1e2e6f947c9.zip | |
Implemented Brush Picker.
Diffstat (limited to 'Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs b/Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs new file mode 100644 index 000000000..d9a096312 --- /dev/null +++ b/Software/Visual_Studio/Tango.BrushPicker/Utils/TextBoxBehavior.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; + +namespace Tango.BrushPicker +{ + public class TextBoxBehavior + { + public static bool GetSelectAllTextOnFocus(TextBox textBox) + { + return (bool)textBox.GetValue(SelectAllTextOnFocusProperty); + } + + public static void SetSelectAllTextOnFocus(TextBox textBox, bool value) + { + textBox.SetValue(SelectAllTextOnFocusProperty, value); + } + + public static readonly DependencyProperty SelectAllTextOnFocusProperty = + DependencyProperty.RegisterAttached( + "SelectAllTextOnFocus", + typeof(bool), + typeof(TextBoxBehavior), + new UIPropertyMetadata(false, OnSelectAllTextOnFocusChanged)); + + private static void OnSelectAllTextOnFocusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var textBox = d as TextBox; + if (textBox == null) return; + + if (e.NewValue is bool == false) return; + + if ((bool)e.NewValue) + { + textBox.GotFocus += SelectAll; + textBox.PreviewMouseDown += IgnoreMouseButton; + } + else + { + textBox.GotFocus -= SelectAll; + textBox.PreviewMouseDown -= IgnoreMouseButton; + } + } + + private static void SelectAll(object sender, RoutedEventArgs e) + { + var textBox = e.OriginalSource as TextBox; + if (textBox == null) return; + textBox.SelectAll(); + } + + private static void IgnoreMouseButton(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + var textBox = sender as TextBox; + if (textBox == null || textBox.IsKeyboardFocusWithin) return; + + e.Handled = true; + textBox.Focus(); + } + } +} |
