Reputation: 5458
I have created code in WPF to let the window remember its last location like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
Rect storedLoc = Properties.Settings.Default.WindowSavedLocation;
this.Top = storedLoc.Top;
this.Left = storedLoc.Left;
}
catch
{
MessageBox.Show("No settings stored !");
}
}
private void Window_Closed(object sender, EventArgs e)
{
Properties.Settings.Default.WindowSavedLocation = RestoreBounds;
Properties.Settings.Default.Save();
}
When I build the application I can see that the app.exe.config file has the setting
WindowSavedLocation
but it just does not save and throws no exception.
Everytime I run the application, it says "No settings stored !".
It's scope is user.
Upvotes: 0
Views: 1632
Reputation: 941465
I repro. The Remarks section of the Window.RestoreBounds property docs is relevant to your problem:
If you query RestoreBounds before the window has been shown or after it has been closed, Empty is returned.
Use the Closing event instead so the RestoreBounds property is still valid.
Upvotes: 3