码迷,mamicode.com
首页 > Windows程序 > 详细

C# Note11:WPF Maskable TextBox for Numeric Values

时间:2017-07-28 01:00:57      阅读:261      评论:0      收藏:0      [点我收藏+]

标签: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 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

标签:init   let   span   ref   intel   accept   most   note   ase   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!