예제 #1
0
        public static void RestoreWindowState(this Bootstrapper bootstrapper, IPersistence persistence)
        {
            if (!bootstrapper.Application.IsRunningOutOfBrowser) return;
            var mainWindow = bootstrapper.Application.MainWindow;

            var windowInfo = persistence.ReadTextFile(WindowSettingsFilename);
            if (string.IsNullOrWhiteSpace(windowInfo)) return;

            try
            {
                var posAndSize = XDocument.Parse(windowInfo).Descendants("MainWindow").FirstOrDefault();
                if (posAndSize == null) return;

                if (bool.Parse(posAndSize.Attribute("IsMaximized").Value))
                    mainWindow.WindowState = WindowState.Maximized;
                else
                {
                    mainWindow.Width = int.Parse(posAndSize.Attribute("Width").Value);
                    mainWindow.Height = int.Parse(posAndSize.Attribute("Height").Value);
                    mainWindow.Top = int.Parse(posAndSize.Attribute("Top").Value);
                    mainWindow.Left = int.Parse(posAndSize.Attribute("Left").Value);
                }
            }
            catch (Exception ex)
            {
                log.Warn("Error setting window position from saved settings! {0}", ex);
                persistence.DeleteFile(WindowSettingsFilename);
            }
        }
예제 #2
0
        public static void RestoreWindowState(this Bootstrapper bootstrapper, IPersistence persistence)
        {
            if (!bootstrapper.Application.IsRunningOutOfBrowser)
            {
                return;
            }
            var mainWindow = bootstrapper.Application.MainWindow;

            var windowInfo = persistence.ReadTextFile(WindowSettingsFilename);

            if (string.IsNullOrWhiteSpace(windowInfo))
            {
                return;
            }

            try
            {
                var posAndSize = XDocument.Parse(windowInfo).Descendants("MainWindow").FirstOrDefault();
                if (posAndSize == null)
                {
                    return;
                }

                if (bool.Parse(posAndSize.Attribute("IsMaximized").Value))
                {
                    mainWindow.WindowState = WindowState.Maximized;
                }
                else
                {
                    mainWindow.Width  = int.Parse(posAndSize.Attribute("Width").Value);
                    mainWindow.Height = int.Parse(posAndSize.Attribute("Height").Value);
                    mainWindow.Top    = int.Parse(posAndSize.Attribute("Top").Value);
                    mainWindow.Left   = int.Parse(posAndSize.Attribute("Left").Value);
                }
            }
            catch (Exception ex)
            {
                log.Warn("Error setting window position from saved settings! {0}", ex);
                persistence.DeleteFile(WindowSettingsFilename);
            }
        }