The simplest approach is to use Properties.Settings
.
Links:
Using settings in WPF (or how to store/retrieve window pos and loc)
Saving window size and location in WPF and WinForms (uses some P/Invoke)
But if your want to store data for many different windows Matthew MacDonald suggest you should create a helper class that stores a position for any window you pass in, using a registry key that incorporates the name of that window.
public class WindowPositionHelper
{
public static string RegPath = "Software\\MyApp\\WindowBounds\\";
public static void SaveSize(Window win)
{
// Create or retrieve a reference to a key where the settings
// will be stored.
RegistryKey key;
key = Registry.CurrentUser.CreateSubKey(RegPath + win.Name);
key.SetValue("Bounds", win.RestoreBounds.ToString());
key.SetValue("Bounds",
win.RestoreBounds.ToString(CultureInfo.InvariantCulture));
}
public static void SetSize(Window win)
{
RegistryKey key;
key = Registry.CurrentUser.OpenSubKey(RegPath + win.Name);
if (key != null)
{
Rect bounds = Rect.Parse(key.GetValue("Bounds").ToString());
win.Top = bounds.Top;
win.Left = bounds.Left;
// Restore the size only for a manually sized
// window.
if (win.SizeToContent == SizeToContent.Manual)
{
win.Width = bounds.Width;
win.Height = bounds.Height;
}
}
}
}
The other approach is as Adam said in creating your custom serializable class, that will contain all the properties you need to store and manipulate with them accross all the life cycle of your app.