WPF and Expression Blend development example: a digital input box for style implementation, wpfblend

Source: Internet
Author: User

WPF and Expression Blend development example: a digital input box for style implementation, wpfblend

Today, we have a very odd method of obscenity, which is rarely used. We do not recommend that you use it too frequently.

First style:

<Style x:Key="NumberTextBox" TargetType="{x:Type FrameworkElement}">            <EventSetter Event="PreviewTextInput" Handler="TextBox_TextInput"/>            <Setter Value="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, namely writing code in xaml.

X: Code Msdn Introduction

Reference style:

<TextBox Height="20" Width="200" Margin="10,0" Style="{StaticResource NumberTextBox}"/>

Source code download:

Http://files.cnblogs.com/youngytj/TextBoxStyle.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.