4
votes

I have a borderless window with resize mode set to canMinimize

WindowStyle="None" 
ResizeMode="CanMinimize" 

When I change my window state to minimized on some button click and restore from taskbar icon then window's activated event is fired.

But when I minimize window from taskbar icon and restore from taskbar icon click then my window does not fire activated event.

1

1 Answers

5
votes

This has nothing to do with the window style. You can try the other styles too and you will observe the same behavior.

The underlying window activation logic is based on the Windows' messages. When you click on the taskbar icon of an active window, the following messages will be sent to the window:

  • WM_ACTIVATE (MSDN) with wParam containing WA_INACTIVE + not minimized

followed by:

  • WM_ACTIVATE with wParam containing WA_ACTIVE + minimized

This causes the WPF window to raise the Activated event even if the window has actually been minimized (see that WA_ACTIVE state?) When you click on the taskbar icon one more time, the window will be restored and will receive the message:

  • WM_ACTIVATE with wParam containing WA_ACTIVE + not minimized

But since the window "was" already active, there will be no Activated event. I would consider it as a Windows' bug (why would we receive a WA_ACTIVE state even if the window is minimized?) Maybe you can ask Microsoft about that.

To overcome this problem, you might use the StateChanged event instead and check the window's state (WindowState.Minimized vs. WindowsState.Normal).