How to get IsActivated notification from the Windows Taskbar? - wpf

My specific issue is not being able to close a WPF Popup/Flyout when anything on the Taskbar is clicked. I have been able handle its closing from just about any other object, but the Taskbar remains a mystery.
I have looked into various ways to get Taskbar information (such as SHAppBarMessage), but it seems I can only know two specific states about the Taskbar, neither of which help me.
Does anyone have ideas?

The Window.Deactivated event is triggered by clicking the taskbar.

Related

C# wpf weird repaint issue

I have experienced this intermittent issue with WPF.
Sometimes, when a Window is shown, it will have nothing except maybe a button visible. And after moving your mouse around and clicking on the window, the rest of it will become visible.
I don't know if this is an issue with WPF or maybe the UI library I am using.
Anyone has seen something like this?
Thank you.

Custom Window Bar

I'm not sure that's the right way to say it, but what I want is to for my wpf main window to have it's own bar that will behave like a taskbar, and any children windows that will be open from the main one will be placed in that bar in a similar way like the taskbar works in windows - a rectangle showing the window name for example, on click it opens you the window, if you click minimize it will minimize it to the bar, and with some option, to get it out of the main window and move it to the real windows taskbar, with another option for putting it back in. The problem is I don't know if this is even possible, and I don't know the name of such an element, so if anyone can give me any tips I'll be really thankful.
I worked on an application years ago (.NET 3.0: first WPF release!) that did exactly that. We ran into a lot of issues getting it to work, but we were pretty successful in the end. One thing we didn't support was moving it to the Windows taskbar.
The best option would be to set an attached property on each Window. This would register a Window with your custom taskbar, so if you wanted to move the Window out of your custom bar, you'd set the property to false. Setting the property to true would add it to the collection of application windows, as well as register event handlers to track the state of the Window.
One of the major pain points for us was getting the Window animations correct. If you're not running in XP, this probably less of an issue, as the animations in Vista (or is it 7?) and above aren't really showing where a Window is going on minimize. In the end, we had to do a lot of low level Win32 (p/Invoke) work for this.
Take a look at AvalonDock and WPF MDI:
http://avalondock.codeplex.com/
http://wpfmdi.codeplex.com/

WPF Taskbar Restore/Minimize doesn't always work

So I have a large WPF application, and there is an icon on the taskbar when the application is running. I would expect that if I click the taskbar icon, the application will restore itself, or minimize if it is already showing, as is standard windows functionality. However, sometimes I have to click several times for this to work. I've done quite a bit of research/programming, but this is one fairly simple item I can not figure out. Any help is appreciated, please let me know if I need to provide more info. I have tested using a jumplist, but my users do not want to right click the icon and then click "restore". They just want to left-click the taskbar icon. .Net 4.0, WPF 4. Thanks in advance everyone.

How can I tell which Silverlight Popup (or ChildWindow) is topmost?

I am trying to hit test in Silverlight applications to find the elements under the mouse cursor.
Normally VisualTreeHelper.FindElementsInHostCoordinates works for this. If there is a Popup open I need to pass in the popup to the hit testing method. If there are multiple popups open, I need to determine the correct (topmost) popup to pass in.
Is there any reliable way to determine which Popup is topmost? I'm doing this in an assembly that may be loaded after the Popups have been opened, so I can't rely on tracking the order in which they are opened.
Thanks for any assistance.
It looks like the new VisualTreeHelper.GetOpenPopups call returns the open Popups in order from bottom to top (or least recently to most recently opened?). So that does what I need.
Posting this answer in case anyone else runs into the same issue.

Windows App Focus: Why does it require a click?

When I have 2 apps open and one has the focus but I want to execute a command in the other app, it requires a click to regain focus and another to execute the command. Is there some good reason why I couldn't take focus on MouseOver? I'm working with a WPF app if that is pertinent. TIA
EDIT: Oddly enough the MouseOvers work without focus.
I would not recommend doing this. This is not a standard way of working in Windows, so you will confuse your users. People are used to clicking into an application (or tabbing) to provide focus.
However, this is a configurable setting via the Accessability Tools in Windows. It can be enabled by choosing "Activate a window by hovering over it with the mouse" globally. Let your users specify this behavior if they want it.
The setting is configurable at a system-wide level. You should never ever override the user's current setting regarding this.
MS Windows Vista -- focus follows mouse (There's also a link on how to do it on XP.)
Edit: Normally, you can click a button on a form and both bring focus to the window and click it at the same time. The origins of the current setting "eating" the initial mouse click that brings focus to a window started as a fix to a bug in the Ribbon UI. The discussion is somewhere in this video: The Story of the Ribbon. Sorry I can't narrow it down more than that, but at least the video is a great insight and work watching - maybe you can send a message to Jensen Harris if you need a faster answer.
Edit 2: I just added a button to a WPF window, and I'm able to click it as long as I can see it - whether or not the window has focus.
You can take focus on MouseOver manually

Resources