-
- golgepapaz
- Posts: 43
- Joined:
[Unity] Numeric TextBox
Hi all,
I'm trying to create numeric textbox, so I register PreviewKeyDown event of textbox and set e.handled true when entered key is nonnumeric but text is changing.
I'm trying to create numeric textbox, so I register PreviewKeyDown event of textbox and set e.handled true when entered key is nonnumeric but text is changing.
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [Unity] Numeric TextBox
TextBox text is managed by TextInput event, so you have to filter characters in the PreviewTextInput event:
Code: Select all
var tb = root.FindName<TextBox>("tb");
tb.PreviewTextInput += tb_PreviewTextInput;
Code: Select all
void tb_PreviewTextInput(BaseComponent sender, TextCompositionEventArgs e)
{
if (e.ch >= '0' && e.ch <= '9')
{
// numeric: OK!
}
else
{
e.handled = true;
}
}
Who is online
Users browsing this forum: Ahrefs [Bot], liangcheng and 3 guests