wpf - XAML Trigger Auto-tab when MaxLength is Reached -
how can incorporate auto-tab when maxlength property reached xaml trigger, datatrigger, propertytrigger, style.trigger, etc. below 2 such options how have accomplished textbox via code-behind. i'm looking apply in xaml style well. thanks.
xaml:
<textbox x:name="mytextbox" text="{binding path=myproperty}" style="{staticresource textboxstyle}" maxlength="5" textchanged="mytextbox_textchanged"> </textbox> code-behind wpf:
private void mytextbox_textchanged(object sender, textchangedeventargs e) { if (mytextbox.text.length == mytextbox.maxlength) { keyboard.focus(nexttextbox); } } private void mytextbox_previewkeydown(object sender, keyeventargs e) { // auto-tab when maxlength reached if (((textbox)sender).maxlength == ((textbox)sender).text.length) { // move focus var ue = e.originalsource frameworkelement; e.handled = true; ue.movefocus(new traversalrequest(focusnavigationdirection.next)); } } }
simply in shell.xaml
<style targettype="textbox"> <eventsetter event="textchanged" handler="mytextbox_previewkeydown"/> </style> and in shell.xaml.cs
private void mytextbox_previewkeydown(object sender, keyeventargs e) { // auto-tab when maxlength reached if (((textbox)sender).maxlength == ((textbox)sender).text.length) { // move focus var ue = e.originalsource frameworkelement; e.handled = true; ue.movefocus(new traversalrequest(focusnavigationdirection.next)); } } }
Comments
Post a Comment