How to block the input method in the TextBox mask in WPF / SL
There is a special case, because in the input method state, TextBox KeyDown event to capture the Key are ImeProcessed, and MSDN said in accordance with the e.ImeProcessedKey to get the real key is also completely pressed Nonsense, from here is also ImeProcessed. Depressed, suddenly an idea, think of the system comes with the PasswordBox is unable to use the input method, so use Reflector to view its source code and found that he made the following static constructor function:
InputMethod.IsInputMethodEnabledProperty.OverrideMetadata(
typeof(PasswordBox),
new FrameworkPropertyMetadata(BooleanBoxes.FalseBox,
FrameworkPropertyMetadataOptions.Inherits,
null,
new CoerceValueCallback(PasswordBox.ForceToFalse)));
Very simple, that is, you can set the inputMethod named IsInputMethodEnabled additional attributes to achieve the shielding input method.
The use of WPF and SL is as follows:
<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>
A very useful but little user knows little function.