我在WPF中创建了代码,让窗口记住它的最后一个位置,如下所示:
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();
}在构建应用程序时,我可以看到app.exe.config文件具有以下设置
WindowSavedLocation但它不会保存,也不会抛出任何异常。
每次我运行应用程序时,它都会显示“没有存储设置!”
它的作用域是用户。
发布于 2010-12-26 01:20:59
我是复制品。Window.RestoreBounds属性文档的备注部分与您的问题相关:
如果在窗口显示之前或关闭之后查询RestoreBounds,则返回Empty。
请改用结束事件,以便RestoreBounds属性仍然有效。
https://stackoverflow.com/questions/4530375
复制相似问题