This article describes what to enhance the WPF and make TextBox
it accept just numeric (integers and floating point) values. T He second goal is make the TextBox
smart enough to make it easier to input numerics. This TextBox
is a easy means to provide the with some kind of intelligence, not just rejecting non-numeric symbols. The provided extension also allows setting minimum and/or maximum values.
If you search on the net, you'll probably find some solutions for this problem where developers create their own vers Ions of the TextBox
either by inheriting from it or creating a custom/user Controls that include th e standard wpf TextBox
. Most other solutions has one major drawback-you would need to replace your TextBox
definitions with yo ur new masktextbox
. Sometimes, it is isn't painful, sometimes, it is. The reason I chose another solution is and the my case, such kind of changes would was painful.
The approach I ' m proposing here's the usage of WPF attached Properties, which basically is similar to Dependency Propert ies. The major difference among these to be that Dependency properties were defined inside the control, but attached properties is defined outside. For instance, was TextBox.Text
a Dependency property, but was an Grid.Column
attached property.
Https://www.codeproject.com/Articles/34228/WPF-Maskable-TextBox-for-Numeric-Values
Simple Numeric Textbox:https://www.codeproject.com/articles/30812/simple-numeric-textbox
C # NOTE11:WPF maskable TextBox for Numeric Values