views:

367

answers:

1

I want to save and restore the window position of my WPF application. I want to make the code robust to use with multiple monitors who's number and relative location can change (I want to avoid opening my application off-screen when the monitor configuration has changed inbetween invocations).

I know of the Screen class in System.Windows.Forms, but I don't want to take a dependency on that assembly just for this feature.

+1  A: 

Windows will keep your application on the screen even if you use corrdinates which are now outside fo the viewable range. Just persist DesktopLocation, Size, and WindowState (to see if the app was maximized). Be sure not to save these settings if the app was closed when minimized.

Nick
DesktopLocation is in System.Windows.Forms. I am looking for a solution for WPF instead. I can persist and restore Left, Top, Width, and Height, but when I restore them Left is not respected (i.e., negative values are not pushed to the left of the main screen).
Philipp Schmid