c# - How to disable / cancel undo button in xamarin -


i creating application has entry. trying restrict entry allow numeric input. have tried using keyboard = "numeric". ipad, however, keyboard has more characters numbers. had restrict entered. when however, if user types in parenthesis, example, stop character being entered. if user presses undo, crashes. assume because software keyboard separate app, looking parenthesis character, isn't there. here code:

private void entry_textchanged(object sender, textchangedeventargs e)     {         entry theentry = (entry)sender;         string entrytext = theentry.text;         if(entrytext != null && entrytext.length != 0)         {             char themostrecentinput = entrytext[entrytext.length - 1];             if(!extension.isnumeric(themostrecentinput))             {                 theentry.textchanged -= entry_textchanged;                 theentry.text = e.oldtextvalue;                 theentry.textchanged += entry_textchanged;             }         }     } 

thanks help!

i in entry custom renderer way you can control input via shouldchangecharacters , not have kludge allowing input , having remove handler , change text old value...

here quick example allows numeric, automatically handles clipboard pasting non-numeric strings disallowed. using nscharacterset.decimaldigits character set internationalized os, allow/disallow chars of choosing.

you include haptic, visual or audio feedback on disallowed/rejected entries...

[assembly: exportrenderer(typeof(numericentry), typeof(numericentryrenderer))] namespace forms_pcl_tester.ios {     public class numericentryrenderer : entryrenderer     {         protected override void onelementchanged(elementchangedeventargs<xamarin.forms.entry> e)         {             base.onelementchanged(e);             if (e.newelement != e.oldelement)                 if (control != null)                 {                     control.keyboardtype = uikeyboardtype.numbersandpunctuation;                     control.shouldchangecharacters += (uitextfield textfield, nsrange range, string replacementstring) =>                      {                          foreach (var achar in replacementstring)                              if (!nscharacterset.decimaldigits.contains(achar))                                  return false;                          return true;                      };                 }         }     } } 

Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

meteor - inserting data to database gives error "insert failed: Method '/texts/insert' not found" -