Pregunta

I am developing WP7 application. I am new to the WP7. I am also new to the silverlight. I have a textbox in my application. In this textbox user enters the amount. I want to give the facility in my application so that user can enter the float amount ( for e.g. 1000.50 or 499.9999). The user should be able to enter either two digit or four digit after the '.' .My code for the textbox is as follows.

<TextBox InputScope="Number" Height="68" HorizontalAlignment="Left" Margin="-12,0,0,141" Name="AmountTextBox" Text="" VerticalAlignment="Bottom" Width="187" LostFocus="AmountTextBox_LostFocus" BorderBrush="Gray" MaxLength="10"/>

I have done the following validations for the above textbox.

public void AmountTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            foreach (char c in AmountTextBox.Text)
            {                
                if (!char.IsDigit(c))
                {
                    MessageBox.Show("Only numeric values are allowed");
                    AmountTextBox.Focus();
                    return;
                }
            }
        }

How to resolve the above issue. Can you please provide me any code or link through which I can resolve the above issue. If I am doing anything wrong then please guide me.

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top