Help to know what's wrong [closed]

-1
//Função para permitir somente números e ponto
private void ApenasValorNumerico(object sender, KeyEventArgs e)
{
    TextBox txt = (TextBox)sender;
    if (e.Key != Key.Back)
    {
        if (Convert.ToChar(e.Key) == '.')
            e.Handled = (txt.Text.Contains('.'));
        else
            e.Handled = true;
    }
}

Well, I found this code in another post, and I modified it to try to use it in my WindowsPhone application, but I do not know where the error is .. I'm a beginner.. Thanks in advance for any help ..

PS: Actually there is no error, it just does not work .. the method is called but it does not allow inclusion in the textbox .. none of the "keys" works, neither numbers nor point.     

asked by anonymous 16.01.2016 / 03:37

1 answer

2
___ erkimt ___ Help to know what's wrong [closed] ______ qstntxt ___
  if (System.Text.RegularExpressions.Regex.IsMatch(e.Key.ToString(),"[0-9]|."))
   {
      e.Handled = false;
   }
   else
   {
       else e.Handled = true;
   }

Well, I found this code in another post, and I modified it to try to use it in my WindowsPhone application, but I do not know where the error is .. I'm a beginner.. Thanks in advance for any help ..

PS: Actually there is no error, it just does not work .. the method is called but it does not allow inclusion in the textbox .. none of the "keys" works, neither numbers nor point.     

______ ___ azszpr108653

You can make the following comparison:

  if (System.Text.RegularExpressions.Regex.IsMatch(e.Key.ToString(),"[0-9]|."))
   {
      e.Handled = false;
   }
   else
   {
       else e.Handled = true;
   }
    
___
16.01.2016 / 04:09