How to shield input methods in textbox shielding in WPF/SL?

Source: Internet
Author: User

Today, I encountered a depressing problem. Because in the input method state, all the keys captured in the keydown event of textbox are imeprocessed, and according to E. imeprocessedkey is used to obtain the real press key, which is also called imeprocessed. When I was depressed, I suddenly got a brainwave and thought that the input method could not be used in the passwordbox provided by the system. So I checked it with reflector.Source codeIt is found that he made the following settings in the static constructor:

Code

Inputmethod. isinputmethodenabledproperty. overridemetadata ( Typeof (Passwordbox ), New Frameworkpropertymetadata (booleanboxes. falsebox, frameworkpropertymetadataoptions. inherits, Null , New Coercevaluecallback (passwordbox. forcetofalse )));

Simply put, you can set an additional attribute named isinputmethodenabled of inputmethod to shield the input method.

The methods used in WPF and SL are as follows:

WPF

< Window X: Class = "Wpfmodelviewapplication1.views. mainview"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: Input = "CLR-namespace: system. Windows. input; Assembly = presentationcore"
Title = "Main Window" Height = "400" Width = "800" >
< Dockpanel >
< Grid X: Name = "Grid1" >
< Textbox X: Name = "TB" Width = "100" Horizontalalignment = "Right" Margin = "0,164,122,128" Input: inputmethod. isinputmethodenabled = "False" />
</ Grid >
</ Dockpanel >
</ Window >
SL

< Usercontrol X: Class = "Silverlightapplication1.mainpage"
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: Input = "CLR-namespace: system. Windows. input; Assembly = system. Windows" >
< Stackpanel X: Name = "Layoutroot" >
< Textbox X: Name = "Tb1" Width = "100" Height = "100" Input: inputmethod. isinputmethodenabled = "False" />
</ Stackpanel >
</ Usercontrol >

 

A small feature that is very practical but rarely known. I hope it can help you.

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.