2
votes

If I have problems with WPF, then it always concerns the Focus-Management. There are cases, my App loses totally focus so that another application gains the focus and my app goes in the background. This happens mainly if some windows in my app will be closed. Is this a known problem of WPF. Does someone else has similar problems?

I already opened another thread to this, but no one could help, maybe it was a little to detailed. Therefore this here is the short version.

UPDATE

It seems that I have found a simple hack that helps prevent the behavior I describe in the other thread. If you have the same problem, try if it helps you. If you have an explanation, there is a bounty open for...

I leave this post open for a few days, may be someone has a good general input to the WPF-focus problematic. Probably I don't understand the logic behind it, but until I will understand, this is IMO really the worst part of WPF (what IMO is a really fantastic product). If I have to tell someone with what I had problems the last years within WPF, it would be: Focusmgmt, Focusmgmt, and one time more Focusmgmt.

2
WAG here: Change your keyboard/mouse out. If you have a touch screen, research the manufacturer for ghost clicks. If you are on a laptop, update your pad drivers or disable it completely.user1228

2 Answers

2
votes

For losing focus for the entire app make sure you set the Owner property on all windows before you show them.

For losing focus inside the app, usually this happens when some control you didn't think off is getting but not showing anything (for example some random StackPanel or Grid used for layout), you have to hunt those down and add Focusable="false"

1
votes

+1 As I have also faced similar issues in my application. I am working on a VS like application(user can add(from toolbox) and configure controls in a Canvas) and focus is lost mysteriously after various commnads are executed like Delete etc. I have to use Canvas.Focus() explicitly to reset the focus and that too doesn't work sometimes.