Ejemplo n.º 1
0
 public void SaveWindowPosition(PluginConfiguration config)
 {
     if (_mainWindow != null) {
         // Save window position
         config.WindowState = _mainWindow.WindowState;
         config.WindowTop = _mainWindow.Top;
         config.WindowLeft = _mainWindow.Left;
         config.WindowWidth = _mainWindow.Width;
         config.WindowHeight = _mainWindow.Height;
     }
 }
Ejemplo n.º 2
0
        public MainWindow CreateMainWindow(PluginConfiguration config, IViewModel viewModel)
        {
            var window = new MainWindow {
                DataContext = viewModel,
            };

            FormStartPosition? startPosition = null;

            // Restore window position/size
            if (config.WindowState.HasValue) {
                // Set window state
                window.WindowState = config.WindowState.Value;

                // Set position if not maximized
                if (config.WindowState.Value != WindowState.Maximized) {
                    double left = 0;
                    double top = 0;

                    // Set left
                    if (config.WindowLeft.HasValue) {
                        startPosition = FormStartPosition.Manual;
                        window.WindowStartupLocation = WindowStartupLocation.Manual;
                        window.Left = left = Math.Max(config.WindowLeft.Value, 0);
                    }

                    // Set top
                    if (config.WindowTop.HasValue) {
                        startPosition = FormStartPosition.Manual;
                        window.WindowStartupLocation = WindowStartupLocation.Manual;
                        window.Top = top = Math.Max(config.WindowTop.Value, 0);
                    }

                    // Set width
                    if (config.WindowWidth.HasValue) {
                        window.Width = Math.Min(config.WindowWidth.Value, SystemParameters.VirtualScreenWidth - left);
                    }

                    // Set height
                    if (config.WindowHeight.HasValue) {
                        window.Height = Math.Min(config.WindowHeight.Value, SystemParameters.VirtualScreenHeight - top);
                    }
                }
            }

            window.ShowInTaskbar = window.WindowState == WindowState.Minimized;

            _mainWindow = window;
            _mainWindowHandle = new WindowInteropHelper(_mainWindow).Handle;

            CreateInternalPlayerWindow(startPosition);

            OnMainWindowLoaded(window);

            return window;
        }