C
C#2y ago
Elio

❔ 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
Elio
ElioOP2y ago
sibber
sibber2y ago
wpf?
Elio
ElioOP2y ago
yes
sibber
sibber2y ago
handle PreviewTextInput and validate set eventArgs.Handled to true if its not valid
Elio
ElioOP2y ago
so 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 ?
sibber
sibber2y ago
no PreviewTextInput not KeyDown then you check if the text is valid, in your case if its a decimal number
Elio
ElioOP2y ago
aww 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
sibber
sibber2y ago
sure you can also use TryParse
Elio
ElioOP2y ago
i will do that once i've make sure that my string is a decimal 🙂
sibber
sibber2y ago
you can use that to check if its a decmial
Elio
ElioOP2y ago
oohhhh i thought it just convert my number from string to double or others
sibber
sibber2y ago
also returns whether it can be converted or not
Elio
ElioOP2y ago
insane 😮 now i just need to avoid multple dot thanks a lot you give me all the int i needed
sibber
sibber2y ago
np
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server