Is there any way to catch the Up/Down arrow keys in a WPF TextBox (System.Windows.Controls.Textbox) and allow them to alter the text? I've read about overiding the ProcessCmdKey method for a Windows Forms TextBox (System.Windows.Forms.TextBox), and it worked fine, but that TextBox is not nearly as flexible as the WPF one. Is there a similar method to accomplish this without having to use the old Windows Forms TextBox?
For my example, I have a TextBox that has a numeric text-mask. I want to be able increase/decrease the numeric value by using the up and down arrow keys.
You could add event handlers to KeyUp and/or KeyDown, if that doesn't get what you need, using PreviewKeyUp and/or PreviewKeyDown should.
Related
I just have a form, and using this.Controls.Add in the form I have added a container control which basically fills the whole background area of the form (and contains many other controls like datagridviews, comboboxes etc), so I can't click off of it.
Now, in the form class, I want to add some keyboard shortcuts.. Like, F5 saves my work for instance. Anyway, I have hooked up to the control's keydown even in the form class, but, it doesn't seem to fire!
Can anyone tell me why?
Thanks,
Isaac
It would probably have helped if you would have described which control you were adding. You are most likely adding a control that is trying to read the keyboard events. For the form to still get those events, change this property:
this.KeyPreview = True;
I have a textbox and some labels inside the data template of bounded listbox.
When I click on any label the whole item is highlighted in blue, but when I click directly on a different textbox the selection does not change.
Is there a way to make the selection of the listbox change even when a textbox is clicked?
thanks
This is what I've exactly asked few days ago, see post: "WPF: Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area"
basically there are few solutions, using code behind and XAML, but I've not verified latter approach yet
The reason is because the TextBox handles the click event in order to receive focus. There are a number of ways to handle this, including but not limited to:
stop the TextBox handling mouse events (which prevents the user from focussing it using the mouse)
use an eventhandler when the TextBox gains focus (or PreviewClick or similar), to select the parent ListItem
The use of tab keys within the WPF datagrid is my big issue these days. Oh, the datagrid. Why does it behave like it does anyway... :S
1st: I want to disable the ability to use the tab key within the datagrid. Once the focus is set within the datagrid I want to use the arrow keys to navigate.
2nd: If the user hits the tab key within the datagrid I want to jump out of the datagrid and get focus of the next element after the datagrid in the correct tab order.
Any way I can accomplish this?
You could subscribe to the KeyUp or PreviewKeyUp event, listen for a tab and respond accordingly.
I am using ListBox for having RadioButtonList behaviour (that's what people recommend as there is no inherent radio button list in WPF). The listbox is bound to a ViewModel.
Now, whenever user changes the selection on listbox, I want to check whether user has some unsaved data on the part of screen and prompt accordingly (typical yes,no,cancel). If I use SelectionChanged event, the selection has already occured and hence, prompting is of no use. And there doesn't seem to be any SelectionChanging event.
I am am not sure but can I mimic SelectionChanging behaviour by using WPF binding validation rules?
Or should I use MouseButtonDown event? Would that lead to problems?
You don't need to put them in a listbox, the are group-able like so:
<RadioButton GroupName=“One“ IsChecked=“True“/>
Notice the GroupName, this holds the collection together, as for the rest of your question I am having a slight issue understanding what you need, sorry :(
I want to use a Similar control like domainUPDown control in my wpf application.
How to do the using infragistic or any other way.
I need a control like a textbox with up and down button.
How to do it?
That is ok, but i need tat up and down button for mouse click
Thanks,
With Infragistics use the XamNumericEditor control. The Up and Down arrow keys make the value change.