views:

44

answers:

1

I have a small out-of-browser app, and want to save and restore its window width+height+state between sessions using IsolatedStorageSettings.ApplicationSettings.

I'm trying to save settings like this (on Application_Exit):

IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
Window mainWindow = Application.Current.MainWindow;

appSettings["WindowTop"] = mainWindow.Top;
appSettings["WindowLeft"] = mainWindow.Left;
appSettings["WindowWidth"] = mainWindow.Width;
appSettings["WindowHeight"] = mainWindow.Height;
appSettings["WindowState"] = (UInt32)mainWindow.WindowState;

The bad thing is when an app is maximized, this code stores the Width, Height, Left and Top of maximized window, not the normal size/position (before maximization).

Can I get the normal window size and position somewhere?

If I'll have that values on Application_Startup, I can set normal size/position and then set WindowState, so the window position will be restored correctly after returning from maximized state.

+1  A: 

In your case I would hook SizeChanged event on your root element and based on WindowState I would save new window size or ignore it if window is maximized.

Denis
What about changing window's position without resize? I want to store Top/Left of main window too.
Andrew
Window class in silverlight has very limited functionality. At this time I can't think of any way of knowing when window position is changed. You could check Top/Left properties once every x seconds using DispatcherTimer, but that is rather inelegant solution
Denis
Thanks a lot, Denis
Andrew