其实挺简单的:![](https://www.cnblogs.com/Emoticons/qface/055242240.gif)
Step1: 加一个新的 User-Scoped setting:
![](https://www.cnblogs.com/images/cnblogs_com/jacksonyin/SaveWindowLocation.png)
Step2: Save Window Location
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
Properties.Settings.Default.WindowPosition = this.RestoreBounds;
Properties.Settings.Default.Save();
}
Step3: Load Window Location
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
private void Window_Initialized(object sender, EventArgs e)
{
try
{
Rect bounds = Properties.Settings.Default.WindowPosition;
this.Top = bounds.Top;
this.Left = bounds.Left;
// Restore the size only for a manually sized window.
if (this.SizeToContent == SizeToContent.Manual)
{
this.Width = bounds.Width;
this.Height = bounds.Height;
}
else
{
this.Width = 1024;
this.Height = 768;
}
}
catch
{
this.Top = 0;
this.Left = 0;
this.Width = 1024;
this.Height = 768;
}
}
好了,搞定了.
private void Window_Initialized(object sender, EventArgs e)
{
try
{
Rect bounds = Properties.Settings.Default.WindowPosition;
this.Top = bounds.Top;
this.Left = bounds.Left;
// Restore the size only for a manually sized window.
if (this.SizeToContent == SizeToContent.Manual)
{
this.Width = bounds.Width;
this.Height = bounds.Height;
}
else
{
this.Width = 1024;
this.Height = 768;
}
}
catch
{
this.Top = 0;
this.Left = 0;
this.Width = 1024;
this.Height = 768;
}
}