示例#1
0
        private static void FitRestoreData(RestoreWindowData data)
        {
            if (data.Width > SystemParameters.VirtualScreenWidth)
            {
                data.Width = SystemParameters.VirtualScreenWidth;
            }
            if (data.Height > SystemParameters.VirtualScreenHeight)
            {
                data.Height = SystemParameters.VirtualScreenHeight;
            }

            if (data.Left < SystemParameters.VirtualScreenLeft)
            {
                data.Left = SystemParameters.VirtualScreenLeft;
            }
            else if (data.Left + data.Width > SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth)
            {
                data.Left = SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - data.Width;
            }

            if (data.Top < SystemParameters.VirtualScreenTop)
            {
                data.Top = SystemParameters.VirtualScreenTop;
            }
            else if (data.Top + data.Height > SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight)
            {
                data.Top = SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - data.Height;
            }
        }
示例#2
0
        public void Restore()
        {
            string            filePath = GetFilePath(settings, window);
            RestoreWindowData data     = StdUtils.XmlDeserializeFile <RestoreWindowData>(filePath);

            FitRestoreData(data);

            WindowState restoreState = settings.OverrideMinimized.HasValue && data.WindowState == WindowState.Minimized ?
                                       settings.OverrideMinimized.Value : data.WindowState;

            if (settings.RestoreWindowState && !window.IsLoaded)
            {
                window.WindowState = restoreState == WindowState.Normal ? WindowState.Normal : WindowState.Minimized;
            }

            if (settings.RestoreLeft)
            {
                window.Left = data.Left;
            }
            if (settings.RestoreTop)
            {
                window.Top = data.Top;
            }
            if (settings.RestoreWidth)
            {
                window.Width = data.Width;
            }
            if (settings.RestoreHeight)
            {
                window.Height = data.Height;
            }

            if (settings.RestoreWindowState)
            {
                if (!window.IsLoaded)
                {
                    window.Loaded += Window_Loaded;
                }
                else
                {
                    window.WindowState = restoreState;
                }
            }

            void Window_Loaded(object sender, RoutedEventArgs e)
            {
                window.Loaded -= Window_Loaded;

                window.WindowState = restoreState;
            }
        }
示例#3
0
        public void Store()
        {
            string            filePath = GetFilePath(settings, window);
            RestoreWindowData data     = new RestoreWindowData()
            {
                Left        = window.RestoreBounds.Left,
                Top         = window.RestoreBounds.Top,
                Width       = window.RestoreBounds.Width,
                Height      = window.RestoreBounds.Height,
                WindowState = window.WindowState,
            };

            StdUtils.XmlSerialize(filePath, data);
        }