views:

998

answers:

3

I'm learning Silverlight 3 and, in all of my tests, when I press the browser refresh button, the SL application restarts.

Is there any way to avoid this?

+5  A: 

Isolated Storage. You can save you setting, and application state there...

http://silverlight.net/learn/learnvideo.aspx?video=65677

I would still recommend building your silverlight app in a way that saves enough state that a refresh will bring the user back to a meaningful location.

you might want to look at Silverlight3 Navigation : http://www.davidpoll.com/?p=88

If you are having a huge issue with a user refreshing the application, you could attempt to pop a new browser window that has no menubar and tool bar... but you will run into popup blockers...

http://www.webdevelopersnotes.com/tutorials/javascript/creating_opening_new_window_pop_ups_javascript.php3

BigBlondeViking
+3  A: 

Afaik you can't cancel an application restart like that. What you can do is handle the Exit event in your App.xaml.cs and save the settings to IsoStore as suggested above, then load them in the Startup event (same class). I guess you could make it a seamless transition by taking them back to the state that was present during the Exit event.

James Cadd
+2  A: 

It's not possible to keep the state 'automatically'. However, using the navigation framework in SL3 you can achieve some level of statefulness: when you click 'Refresh' the application will restart but will navigate to the same page it was before.

Something similar is done in Quince: http://quince.infragistics.com/#/Search/ViewPattern$pattern=Action+Links

The part of the URL after # is read by the application and makes it navigate to the same place always.

This will not work if there's a lot of data to persist, as you need to keep state in the URL. However, has the nice side effect of enabling deep linking.

aaguiar