Silverlight 4 idle status determination

What is the best way to determine the idle state for a silverlight application? I have read quite a few articles on the web by now, and usually they are either intended for wpf / mobile applications, etc.

I created a DispatcherTimer that locks the screen after 5 minutes, and it seems that I will need to go to each widget on each screen (my application has about 4-5 screens) and add a mousebuttondown or mouseenter event handler to reset this timer. This doesn't seem efficient, but just adding a handler to layroot doesn't help either.

Any useful suggestions?

thanks

+6
source share
2 answers

You do not need to change each control. If you add the following code at startup:

Application.Current.RootVisual.MouseMove += new MouseEventHandler(RootVisual_MouseMove); Application.Current.RootVisual.KeyDown += new KeyEventHandler(RootVisual_KeyDown); 

With the following event handlers:

 private void RootVisual_KeyDown(object sender, KeyEventArgs e) { idle = false; } private void RootVisual_MouseMove(object sender, MouseEventArgs e) { idle = false; } 

Where idle is the variable that you use in your DispatcherTimer Tick event to check what is happening or not.

As events accumulate in the tree, this should work for all of your controls.

+5
source

Processed events will not depend on root management. Instead, you should use the AddHandler method with handledEventsToo = true .

+2
source

Source: https://habr.com/ru/post/891198/


All Articles