Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class UnNumberBehavior : 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. if (sender is TextBox)
  12. {
  13. Regex regex = new Regex("[А-Яа-я]");
  14. e.Handled = regex.IsMatch(e.Text);
  15. }
  16. }
  17.  
  18. protected override void OnDetaching()
  19. {
  20. base.OnDetaching();
  21. this.AssociatedObject.TextInput -= OnTextChanched;
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement