Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any tips on debugging focus issues in WPF?

Specifically, I have a button that opens a non-modal child window. Something in the main window steals the focus away from the child window as it opens.

The fully general approach is to comment out parts of code until the problem goes away. I'm looking for faster methods.

like image 521
CannibalSmith Avatar asked Jul 28 '10 09:07

CannibalSmith


People also ask

How do I debug WPF application in Visual Studio?

You can use the Live Visual Tree to explore the visual tree of a WPF object and view the WPF dependency properties for the objects in that tree. You can use the WPF Tree Visualizer to explore the visual tree of a WPF object and view the WPF dependency properties for the objects in that tree.

What is focus WPF?

In WPF there are two main concepts that pertain to focus: keyboard focus and logical focus. Keyboard focus refers to the element that receives keyboard input and logical focus refers to the element in a focus scope that has focus.


1 Answers

I'm using Snoop to do this right now.

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.

like image 130
stone Avatar answered Oct 12 '22 06:10

stone