views:

120

answers:

1

What's the simplest way in Silverlight to detect the user is not active? i.e. no mouse input and keyboard input for a period of time.

I tried monitoring the mouse events, keyboard events and the focus events of the root visual but it doesn't seem enough. For example, a popup window may be open and these events won't reach the root visual.

Maybe javascript solution?

And then comes the other problem. When the application is idle I would like it to appear gray (just like ChildWindow behavior). And I would like it to appear like this even if there is an open ChildWindow or a simple Popup at the moment.

A: 

Are you sure the child window doesn't bubble? It is a routed event ... didn't realize that.

If not, just create a contract like:

ILastActivity : INotifyPropertyChanged 
void Touch();
DateTime LastActivity { get; private set; }

Then you could create an attached behavior, a base class, or use any other mechanism to simply register the key events on your views. They all would call "Touch" when fired, and your timer would inspect LastActivity to determine it. Might be something you can do with automation peers as well, worth looking into.

Jeremy Likness
The problem is that the ChildWindow does not appear in the visual tree under `Application.RootVisual`.
AnthonyWJones
Understood - hence the contract that the childwindow can communicate with as well, to broadcast the updates.
Jeremy Likness