I'm using the latest version of Xceed.Wpf.Toolkit.dll and I'm having an issue with the IntegerUpDown as well as the DoubleUpDown. I'm unable to enter values through the keyboard. Only the mouse is allowed to change values.
<xctk:IntegerUpDown x:Name="UpDownQuantity" Increment="1" Height="22" Width="85" ValueChanged="UpDownQuantityOnValueChanged"/>
Is there something specific I need to add to allow keyboard input either through number pad or number row on keyboard?
For those who may not read comments the op solved this himself :
#netniV the issue was I'm calling and showing the WPF window from WinForms. In order to pass the input to the WPF controls, you have to call ElementHost.EnableModelessKeyboardInterop(wpfwindow).
Related
I faced a strange issue when trying to support both keyboard and Narrator accessibility.
In the following XAML code:
<StackPanel>
<CheckBox Name="CheckBox"
AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text)}">
<AccessText >C_heck me</AccessText>
</CheckBox>
</StackPanel>
Default Windows 10 Narrator reads "C underscore heck me CheckBox unchecked".
Is there any way to keep keyboard navigation and to get readings from the Narrator as "Check me checkbox unchecked"?
Please note, the code above is an example and I have a lot of places where similar issues occur. I was already tried to add a converter and use it with AutomationProperties.Name but it caused an application slowness.
Your approach of using your own (say) AccessTextToAutomationPropertiesNameConverter() which strips the underscore, would be an attractive way to go for some apps. What was the performance impact in your app when you did that, (and how many controls were having to run through the converter)? Did your converter have a Mode of OneTime? Another option would be to have separate localized strings for the AutomationProperties.Name and the AccessText, but I can see how that's not attractive given that it'll increase the localization costs.
I have a WPF MVVM data form window with data validation. A lot of the controls are text boxes. Currently, the data binding trigger is set to the default, i. e. loss of focus. This means that a field is only validated when it is likely to be filled out completely. So when deleting a number and typing another number, the transient empty value will not be displayed as input error.
But a drawback is that the Save button can only be enabled when the focus moves out of the text box. (No matter where, just out of the edited control. Assuming there is anything else focusable.) If this is the only change, the user waits for the Save button to be available and nothing happens. For the Save button, I'd like to use an immediate binding trigger. How can that be done?
Edit: Forgot to mention that my Save button (which uses ICommand) is only enabled when the input is determined modified and valid. So the data will remain unmodified until data binding updates it, and that won't happen until the focus moves to another control.
I actually had a similar question a while back and the solution I ended using was a custom DependencyProperty that kicked off a timer when a key was pressed, and only actually processed the PropertyChange notification if a specific time had passed.
This means the bound property doesn't get updated (and validated) unless the user pauses in typing for a set period of times.
The code can be found here (may need a bit of cleanup), and it is used like this:
<TextBox
local:DelayedUpdateBehavior.TargetProperty="{x:Static TextBox.TextProperty}"
local:DelayedUpdateBehavior.Milliseconds="1000"
Text="{Binding MyTextProperty, UpdateSourceTrigger=Explicit}" />
Edit: Actually this link might be better. It's a markup extension so you can use it directly from your binding. I can't remember which of these two methods I used in the past, but I know it was one of them :)
<TextBox Text="{local:DelayBinding Path=MyTextProperty, Delay='00:00:01'}" />
Assuming you're using an ICommand type interface for the button click event:
You can...Implement string properties with INotifyPropertyChanged and bind them to your textbox controls. Now in your Command canexecute method you can check to see if the property is !nullorempty.
e/ grammar
Set your Binding's UpdateSourceTrigger property to PropertyChanged. The default for TextBoxes is LostFocus.
Update: So you want to have data binding working on your TextBox and only allow numbers? Have a look at this question: Create WPF TextBox that accepts only numbers
Or use a converter and bind the Save button's IsEnabled property to your TextBox (maybe using a MultiBinding if there's more than one), and use a converter which determines if the text is a valid number and returns true or false.
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.
There is no built in way to do it.
You'll need to write a bit of code to achieve what you're looking for.
Here is an example of what you need to do: WPF Maskable TextBox for Numeric Values
I haven't used InputScope, however, from the MSDN documentation (here, here, here and here) it appears that WPF's input scope requires a more complicated input e.g.
xmlns:swi should be mapped to System.Windows.Input.
<TextBox>
<TextBox.InputScope>
<swi:InputScope RegularExpression="^(0|(-(((0|[1-9]\d*)\.\d+)|([1-9]\d*))))$" />
</TextBox.InputScope>
</TextBox>
(Regex string found on Google, I haven't checked it.)
Or perhaps:
<TextBox>
<TextBox.InputScope>
<swi:InputScopePhrase>
<swi:InputScopePhrase.Names>Number</swi:InputScopePhrase>
</swi:InputScopePhrase>
</TextBox.InputScope>
</TextBox>
string txt = MessageWrite.Text;
if (txt != "")
{
MessageWrite.Text = Regex.Replace(MessageWrite.Text, "[^a-f ^0-9]", "");
if (txt != MessageWrite.Text)
{
MessageWrite.Select(MessageWrite.Text.Length, 0);
}
}
messageWrite is a textbox name. It restricts from A-F and 0-9. User can modify it :)
I have a numericUpDown picker that's set to a range of acceptable years, defaulting to the current year.
The user can edit the number in the box with the keyboard: say if the number in there is 2011 to begin with, they can press backspace and the number in the box on screen will be 201. However, as far as I know, the value property of the control will never read a number below the minimum I set (1900 in this case).
I need a way to get the number currently in the box on the screen regardless of whether it is in my acceptable range or not. Anyone know how to do this?
Thanks!
You can use the NumericUpDown.Text property to get the current text, then parse to int. It may not look like the property exists, but it's there.
The Text has no affect on the appearance of the NumericUpDown control; therefore, it is hidden in the designer and from IntelliSense.
I'm using the MaskedTextbox for .NET 3.5 SP1, from the WPF toolkit. I've got a MaskedTextbox on a WPF page, it fills fine from a SQL Server database, but when I tried to edit the value nothing at all happens. I can select anything, but typing over it, or pressing the delete key or anything else I can thing of, does nothing to the value there. I want to use this to allow a user to enter or edit a time value, like this: 9:30 AM would appear as "09:30 AM". Here's the XAML that I've specified:
<cusControls:MaskedTextBox x:Name="mtbTime"
Mask="90:00 >LL" Margin="5,0,0,0"
Text="{Binding ElementName=ThisDateTime,Path=TimePart,Converter={StaticResource NullableTimeToUnderscoreConverter}}" />
(This is a part of a user control I'm making called "ThisDateTime".) What am I doing wrong and how do I fix it?
I haven't seen the source for the text box, but ran into something similar myself.
Could it be a problem with your partially-entered text either not matching the mask, or not matching the converter?
Is the UpdateSourceTrigger on the Binding somehow set to UpdateProperty, or is something similar happening in the code-behind?