Virtual keyboard Popup not working on a derived textbox in wpf - wpf

I have a derived class called NumericTextBox that is derived from TextBox.This has all the validationsf for the data to be numeric. Now, i have a popup attached to this textbox in my window. the popup is a virtual keyboard. this lets the user input from both Keyboard and Mouse. but whenever i click a button on the popup, the PreivewTextInput is not getting fired. i raise the keybd_event. Please suggest a solution to this
Regards,
Ankur

Try using Snoop to observe/monitor the events that fire when your application is running.

Related

WPF Popup not automatically closing when raised from a ListBoxItem

I have a User Control with an image in it and when the user clicks the image I use a popup to display a record card. I set StaysOpen="False" and all works perfectly through my application, except when I host it in a ListBox. In this case the Popup refuses to recognise a click away from it. Is there an issue with raising a popup from a ListBoxItem or are there other ways around this?
Maybe, opening Popup using Interactivity commands instead of using a Button could be the issue.
Interactivity is not doing the mouse capture and keyboard focus actions. So, Popup will not have a proper mouse capture reference by using Interactivity commands.
I did find the answer in the end and t was my mistake. The action to raise the popup was done on Mouse Down and the popup was opening and then closing on the mouse up cation. All I did was to change it to Mouse Up and it was fine. Thank you for your answer anyway.

Keyboard navigation not working in WPF window inside Visual Studio

I'm developing a VS-Package that shows a WPF window when a MenuCommand is invoked.
inside this WPF window I have a listBox, which is focused immediatly when the window is loaded.
when I show the window via myWindow.ShowDialog(), the arrow up/down key work as expected as I navigate through the listbox items.
However, when I show the window via myWindow.Show(), the listbox gains focus but the keyboard navigation inside the listbox is NOT WORKING, and the PreviewKeyDown event is not firing.
(instead, the caret inside VS editor is moving).
Please help.
Use Microsoft.VisualStudio.PlatformUI.DialogWindow class as the base class for your modal dialog. This should ensure proper keyboard accelerator handling as well as keeping the dialog consistent with the styling of the existing VS dialogs.

How do I find out where the focus is going in my WPF application?

I have a search screen in my WPF application. The screen is implemented as a UserControl in a TabItem of a TabControl. When the user switches to the Search tab, I want the focus to go into one particular field.
So I added a Loaded event handler to the UserControl tag in the Xaml and I called the Focus method of the control I want to have the initial focus in the Loaded event handler. This worked great until I upgraded the Telerik control library I'm using today. Now, when I switch to the Search tab, the focus is NOT in the field I want to have it, but I can't tell what control does have the focus.
The field I want to have focus already has GotFocus & LostFocus event handlers for other reasons. I remembered that in Win Forms, the LostFocus event handler arguments tell you which control is going to get the focus. So I put a breakpoint in my LostFocus handler & discovered that the arguments to the LostFocus event handler in WPF don't include that information.
How can I figure out where the focus is going without putting GotFocus handlers on every control in my UserControl?
Tony
You can try putting your breakpoint on the LostKeyboardFocus Attached Event instead of the LostFocus Event. It uses the KeyboardFocusChangedEventArgs Class which does have properties that show which element had focus and where the focus is going.
private void textBox1_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
textBox1.Text = ((FrameworkElement)e.NewFocus).Name ;
}
Try to press Tab Key and see if it helps you find the control in focus.
You can also use Snoop as suggested in this Q/A: Any tips on debugging focus issues in WPF?
For starters, Snoop shows the current focused element and the current
FocusScope in the status bar.
You can get it to show you all the GotFocus and LostFocus events:
1. Run your app.
2. Run Snoop.
3. Choose your app in the dropdown.
4. Click the binoculars ("Snoop") button.
5. On the right pane, click the Events tab.
6. Click to bring down the dropdown.
7. Scroll down to the Keyboard section and check GotKeyboardFocus, LostKeyboardFocus, and optionally the PreviewXXX events.
8. Now do what you need to do to manipulate focus and watch the Snoop window.
Similarly you can track the FocusManager events the same way.

ComboBox doesn't raise keyboard and mouse events as expected

I use Silverlight 4.0 and have got problems with ComboBox control. I want to implement a popup menu which will show and hide itself without clicking mouse. It should show when I place cursor on its region - this prt works well. Then it should hide whenever mouse pointer is placed outside of its region for a while. I implemented it with MouseEnter and MouseLeave events. My problem is ComboBox - this control behaves weirdly, in my opinion. Normally I would expect it to raise MouseEnter event when I put the cursor on it and MouseLeave when I put the mouse cursor anywhere else. The real situation is different: Whenever I click the combobox, it opens and shows the list of options, and immediately sends LostFocus and MouseLeave events. So it seems like the control lost keyboard focus and mouse pointer has been moved out of its region, while actually the combobox list of optins is open and active and has keyboard focus in it.
So the question is how can I know in my program what is happening in comboboxes? In order to correctly hide my popup menu, I need to know when the list of options in a combobox is open or closed. I can't see any events for this or any other documentation. (Wanted behavior is: If a combobox is closed, I hide my popup menu based on the position of mouse cursor. If a combobox is open, I never hide my popup menu until user either selects something in the combobox, or closes the combobox.)
Also, if you have got a good experience with a third party combobox replacement, which looks and works similarly AND raises events I need, please let me know.
MSDN has two events listed for ComboBox that you might want to look at.
http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed Occurs when the drop-down portion of the combo box closes.
DropDownOpened Occurs when the drop-down portion of the combo box opens.

How to get notified when a window get focus in WPF?

I want to get notified when I click a window in WPF (I use the GotFocus event), but it only triggers when I click on a Combobox in the window. What I want is to get notified when the the window or any of the controls in the window is clicked. Any ideas of how to do this?
The GotFocus event doesn't get fired when the Window gets focus, it's intended to be used with controls only. The Activated event serves this particular purpose.
Use Activated event instead of GotFocus.
You could try the IsKeyboardFocusWithinChanged event. It should trigger when the keyboard focus is taken by an element of the window, or when it is taken by another window

Resources