首页 > Windows开发 > 详细

C# Note11:WPF Maskable TextBox for Numeric Values

时间:2017-07-28 00:54:19      阅读:427      评论:0      收藏:0      [点我收藏+]

 

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 TextBoxdefinitions 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

 

 

Simple Numeric TextBox : https://www.codeproject.com/Articles/30812/Simple-Numeric-TextBox

 

C# Note11:WPF Maskable TextBox for Numeric Values

原文:http://www.cnblogs.com/carsonzhu/p/7248048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!