❔ WPF Textbox decimal only
Hello, i'd like to know how we are supposed to configure our textbox in order to accept only decimal number ? Currently i've this but i do not find a ny good way to do it
15 Replies
wpf?
yes
handle
PreviewTextInput
and validate
set eventArgs.Handled
to true if its not validso i had this
PreviewKeyDown="TextBox_PreviewKeyDown"
then i just write some code in the method in order to select only the key i want. That it ?no
PreviewTextInput
not KeyDown
then you check if the text is valid, in your case if its a decimal numberaww ok cause preview key check only the last key pressed instead of the whole text
i will look some regex expression or something like this thanks i didn't know there was preview event
sure
you can also use
TryParse
i will do that once i've make sure that my string is a decimal 🙂
you can use that to check if its a decmial
oohhhh i thought it just convert my number from string to double or others
also returns whether it can be converted or not
insane 😮 now i just need to avoid multple dot
thanks a lot you give me all the int i needed
np
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.