Ejemplo n.º 1
0
        /// <summary>
        /// Loads the window settings manually, which is useful if <see cref="AutoLoad"/> is false.
        /// </summary>
        /// <returns>True if the previous settings were re-loaded; false if no previous settings existed.</returns>
        public bool Load()
        {
            bool result = false;

            if (!WindowsUtility.IsInDesignMode(this.Window))
            {
                using (ISettingsStore store = ApplicationInfo.CreateUserSettingsStore())
                {
                    ISettingsNode?settingsNode = this.GetSettingsNode(store, false);
                    if (settingsNode != null)
                    {
                        NativeMethods.LoadWindowPlacement(this.Window, settingsNode, this.LoadStateOverride);
                        result = true;
                    }
                    else if (this.LoadStateOverride != null)
                    {
                        this.Window.WindowState = this.LoadStateOverride.Value;
                    }

                    this.LoadSettings?.Invoke(this, new SettingsEventArgs(store.RootNode));
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves the window settings manually, which is useful if <see cref="AutoSave"/> is false.
        /// </summary>
        public void Save()
        {
            if (!WindowsUtility.IsInDesignMode(this.Window))
            {
                using (ISettingsStore store = ApplicationInfo.CreateUserSettingsStore())
                {
                    ISettingsNode?settingsNode = this.GetSettingsNode(store, true);
                    if (settingsNode != null)
                    {
                        NativeMethods.SaveWindowPlacement(this.Window, settingsNode);
                    }

                    this.SaveSettings?.Invoke(this, new SettingsEventArgs(store.RootNode));

                    // Make sure the settings get saved out.
                    store.Save();
                }
            }
        }