标签:init let span ref intel accept most note ase
This article describes how to enhance the WPF TextBox
and make it accept just numeric (integer and floating point) values. The second goal is make the TextBox
smart enough to make it easier to input numerics. This is an easy means to provide the TextBox
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 in the net, you will probably find some solutions for this problem where developers create their own versions of the TextBox
either by inheriting from it or creating a Custom/User Controls that include the standard WPF TextBox
. Most other solutions have one major drawback - you would need to replace your TextBox
definitions with your new MaskTextBox
. Sometimes, it is not painful, sometimes, it is. The reason I chose another solution is that in my case, such kind of changes would be painful.
The approach I’m proposing here is the usage of WPF Attached Properties, which basically are similar to Dependency Properties. The major difference among these to is that Dependency Properties are defined inside the control, but Attached Properties are defined outside. For instance, TextBox.Text
is a Dependency Property, but Grid.Column
is an Attached Property.
https://www.codeproject.com/Articles/34228/WPF-Maskable-TextBox-for-Numeric-Values
C# Note11:WPF Maskable TextBox for Numeric Values
标签:init let span ref intel accept most note ase
原文地址:http://www.cnblogs.com/carsonzhu/p/7248048.html