Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UnNumberBehavior : Behavior<TextBox>
- {
- protected override void OnAttached()
- {
- base.OnAttached();
- this.AssociatedObject.PreviewTextInput += OnTextChanched;
- }
- private void OnTextChanched(object sender, TextCompositionEventArgs e)
- {
- if (sender is TextBox)
- {
- Regex regex = new Regex("[А-Яа-я]");
- e.Handled = regex.IsMatch(e.Text);
- }
- }
- protected override void OnDetaching()
- {
- base.OnDetaching();
- this.AssociatedObject.TextInput -= OnTextChanched;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement