WPF StringFormat to allow only positive numbers
source link: https://www.codesd.com/item/wpf-stringformat-to-allow-only-positive-numbers.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
WPF StringFormat to allow only positive numbers
I only want to allow positive numbers as user input in my TextBox.
If I input -10
and use
<TextBox Text="{Binding Width, StringFormat={}{0:0.00;0.00}}" />
then it always displays positive numbers, but the Data behind is still negative.
How to do it right?
There are a number of ways to handle this, such as OmegaMan's. But my solution for this would be to not use a textbox at all. Sadly WPF has never been blessed with a spinbox/updown control out of the box, but the extended WPFToolkit does have one. So why waste your time on parsing and handling all the nasty cases? Let the control do the heavy lifting.
<extToolkit:IntegerUpDown Value="{Binding Width}" Minimum="0"/>
Related Articles
Swift ios regex allows only positive numbers 1 and more
How to allow only positive numbers in an EditText
Check if the string contains only positive numbers in Ruby
Regular expression to accept only positive numbers and decimals
Allow only positive decimals
Regex c # only positive numbers
Allow only letters, numbers, and hyphens in the input?
Regular expression in JavaScript to allow only optional numbers to 2 decimal places
Text box to allow only decimal numbers, delete and rewind
Allow only letters, numbers, umlauts, +, - and "in String
How to add only positive numbers in a shell script?
Allow only letters, numbers and foreign letters?
Annotating mvc data to prevent the user from allowing only numeric numbers and special characters
Must C ++ std :: uniform_real_distribution & lt; Double & gt; Generate only positive numbers?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK