Created
August 6, 2012 21:48
-
-
Save rkmax/3278762 to your computer and use it in GitHub Desktop.
Clase de Comportamientos para agregar a los controles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using System.Windows.Controls; | |
namespace Rkmax.Controls | |
{ | |
public class Behaviors | |
{ | |
public static readonly DependencyProperty SelectTextOnFocusProperty = DependencyProperty | |
.RegisterAttached("SelectTextOnFocus", typeof(bool), typeof(Behaviors), new FrameworkPropertyMetadata(false, GotFocus)); | |
public static void SetSelectTextOnFocus(DependencyObject obj, bool value) | |
{ | |
obj.SetValue(SelectTextOnFocusProperty, value); | |
} | |
private static void GotFocus(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
var textbox = d as TextBox; | |
if (null == textbox) return; | |
textbox.GotKeyboardFocus += SelectTextOnFocus; | |
textbox.GotMouseCapture += SelectTextOnFocus; | |
} | |
private static void SelectTextOnFocus(object sender, RoutedEventArgs e) | |
{ | |
if (!(sender is TextBox)) return; | |
((TextBox)sender).SelectAll(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment