<TextBox Name="hrTextBox" MaxLength="1" Text="0" KeyDown="hrTextBox_KeyDown" TextAlignment="Center" InputScope="Number"/>
Add this in your construcor to allow only numbers in text box
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);
minTextBox.InputScope = scope;
private void hrTextBox_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.D0:
case Key.D1:
case Key.D2:
case Key.D3:
case Key.D4:
case Key.Back:
case Key.Delete:
break;
default: e.Handled = true;
return;
}
}
private void minTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (minTextBox.Text != "")
{
if (int.Parse(minTextBox.Text) >= 6)
{
switch (e.Key)
{
case Key.Back:
case Key.Delete:
break;
default: e.Handled = true;
return;
}
}
}
Add this in your construcor to allow only numbers in text box
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);
minTextBox.InputScope = scope;
private void hrTextBox_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.D0:
case Key.D1:
case Key.D2:
case Key.D3:
case Key.D4:
case Key.Back:
case Key.Delete:
break;
default: e.Handled = true;
return;
}
}
private void minTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (minTextBox.Text != "")
{
if (int.Parse(minTextBox.Text) >= 6)
{
switch (e.Key)
{
case Key.Back:
case Key.Delete:
break;
default: e.Handled = true;
return;
}
}
}