Original: WPF and Expression Blend development examples: A style-implemented digital input box
Today to a more kinky techniques, very few people use, but also do not recommend too frequent use.
First-up style:
<Stylex:key= "Numbertextbox"TargetType="{x:type FrameworkElement}"> <EventsetterEvent= "Previewtextinput"Handler= "Textbox_textinput"/> <SetterValue= "False" Property= "inputmethod.isinputmethodenabled"/> </Style> <x:code> <! [Cdata[private void Textbox_textinput (object sender, TextCompositionEventArgs e) { BOOL flag = TRUE; foreach (char c in E.text) {if (C < ' 0 ' | | c > ' 9 ') {flag = false; }} e.handled =!flag; } ]]> </x:code>
In fact, there is only one core, that is, the XAML write code.
X:code MSDN Introduction
Reference style:
<Height= "A" Width= "$" Margin= "10,0" Style =" {StaticResource Numbertextbox} " />
Source code Download:
Http://files.cnblogs.com/youngytj/TextBoxStyle.rar
WPF and Expression Blend development examples: A style-implemented digital input box