I'm searching for a way to implement the InputScope of a Textbox like it is done in Wp7, but using classic WPF.
What I want to achieve is, that the input is restricted to only use decimal numbers. How can I achieve that?
<TextBox Text="{Binding Amount, Mode=TwoWay}" InputScope="Number"/>
InputScope is a valid attribute for classic WPF, but sadly it does not seem to work.
InputScope doesn't force any kind of validation or restriction on the input. It is a hint to input processors (eg. on-screen keyboards, speech recognition) of the kind of data that can be entered in a control.
This value is used only if an IME (like an on-screen keyboard) is activated.
Even in WP7, InputScope doesn't restrict the values that can be entered in a text box. You could still enter unwanted characters if you could install an input processor that ignored InputScope.
If you want to restrict text input to specific characters you will have to use a MaskedTextBox or intercept keystroke events. The code will also be easier to understand.
It may be possible to use InputManager's PreProcessInput event to filter input events using the InputScope but it probably isn't worth the effort.