Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1.  public class TextBoxBehavior : Behavior<TextBox>
  2.     {
  3.        protected override void OnAttached()
  4.         {
  5.             base.OnAttached();
  6.             this.AssociatedObject.PreviewTextInput += OnTextChanched;
  7.         }
  8.  
  9.         private void OnTextChanched(object sender, TextCompositionEventArgs e)
  10.         {
  11.             Regex regex = new Regex("[А-Яа-я]");
  12.             e.Handled = regex.IsMatch(e.Text);
  13.         }
  14.  
  15.         protected override void OnDetaching()
  16.         {
  17.             base.OnDetaching();
  18.             this.AssociatedObject.TextInput -= OnTextChanched;
  19.         }
  20.  
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement