开发者

(Silverlight OOB) How to get the normal width and height of main window to save and restore them

I have a small out-of-browser app, and want to save and restore its window width+height+state between sessions using IsolatedStorageSetting开发者_C百科s.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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜