views:

427

answers:

4

In my project I am sending the window to tray on close. How can I give an animated effect for this ie, the movement from the current window position to tray. And also the reverse, means on double clicking on the notifyicon in tray, the window is coming to front?

+1  A: 

I've not done much in WPF so please bear that in mind.

It seems that this can be done through the windows API using DrawAnimatedRects as described here (Worth reading as it highlights some pitfalls)

This has been converted to VB2005 here

You could build something which encapsulates this functionality but it feels a little hacky to me. In addition, I've not tried to access the API directly from a WPF project - I'm assuming it's possible but can't guarantee it.

Next best suggestion would be to investigate the Windows® API Code Pack for Microsoft® .NET Framework. I haven't had a chance to dig through this yet but there's a chance it may expose the functionality in a managed way.

In short, it looks like the other apps that include this functionality handle it themselves through the API rather than relying on the framework.

Basiclife
A: 

I've found couple of articles that demonstrate animating the window to the system tray, however they're not using WPF, but should point you in the right direction.

Alan
A: 

Hi,

Animating the window into view when the tray icon is double clicked is pretty easy actually because you can simply create a WPF animation or storyboard to move your window from the mouse's current position (right over the tray icon) to where ever you want on screen.

If you add a resizing and opacity animation to it you should get a nice result (but use Storyboard in case of several animations running together).

Animating the window back to the tray icon is a little more tricky because you don't know the exact position of it, so you could have your window minimize to the general direction of the tray icons and have it fade out just before it gets there or any other way around.

You could also save the position if the tray icon when it is clicked to open the window the first time, or try to get the real position using windows API, which i do not recommend.

Good luck.

Shabi_669
A: 

Well, the quick answer to your question would be that it can't be done using WPF. The reason why is that WPF lives inside the chrome of the window you are showing, and you are trying to animate the chrome.

The animation you are trying to achieve can be done, but you would need to use Windows API calls in order to do it. Basiclife's suggestions are a perfect place to start

Kiranu