Exemplo n.º 1
0
        private void UnBlockWindow(WindowKey key)
        {
            var window = _concurrentWindowCollection.Get(key);

            if (ReferenceEquals(window, null))
            {
                return;
            }

            window.Window.Opacity          = 1;
            window.Window.IsHitTestVisible = true;
        }
Exemplo n.º 2
0
        public void CloseWindow(WindowKey key)
        {
            var windowInformation = _concurrentWindowCollection.Get(key);

            if (!ReferenceEquals(windowInformation, null))
            {
                if (!windowInformation.StartedShutdownProcess)
                {
                    windowInformation.Window.Close();
                }
            }
        }
Exemplo n.º 3
0
        /************************************************************************/

        #region Window settings
        /// <summary>
        /// Saves the state of the specified window.
        /// </summary>
        /// <param name="key">The window key that identifies the configuration settings.</param>
        /// <param name="window">The window instance being saved.</param>
        public void SaveWindow(WindowKey key, Window window)
        {
            if (window != null && windowConfig.TryGetValue(key, out WindowConfig config))
            {
                if (window.WindowState != WindowState.Maximized)
                {
                    SetItem((int)window.Width, config.GetPropertyId(WindowConfig.Property.Width));
                    SetItem((int)window.Height, config.GetPropertyId(WindowConfig.Property.Height));
                }

                /* don't save state as minimized. if closed as minmized, will restore as normal */
                int state = (int)(window.WindowState == WindowState.Minimized ? WindowState.Normal : window.WindowState);
                SetItem(state, config.GetPropertyId(WindowConfig.Property.State));
                SetItem((int)window.Left, config.GetPropertyId(WindowConfig.Property.Left));
                SetItem((int)window.Top, config.GetPropertyId(WindowConfig.Property.Top));
            }
        }
Exemplo n.º 4
0
        private Window CreateWindow(Type type, WindowKey windowKey, Action <IResultDataCollection> onWindowClosedAction, WindowKey parentWindowKey, IRegionManager regionManager)
        {
            Window window;

            if (regionManager != null)
            {
                Debug.WriteLine($"view regionmanager: {regionManager.GetHashCode()}");
                SetCurrentRegionManager(regionManager);

                window = _container.Resolve(type, new TypedParameter(typeof(IRegionManager), regionManager)) as Window;
                RegionManager.SetRegionManager(window, regionManager);
            }
            else
            {
                window = _container.Resolve(type) as Window;
            }

            if (ReferenceEquals(window, null))
            {
                return(null);
            }

            var windowInformation = new WindowInformation(windowKey, parentWindowKey, window, onWindowClosedAction);

            if (ReferenceEquals(parentWindowKey, null))
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            else
            {
                var parent = _concurrentWindowCollection.Get(parentWindowKey);
                window.Owner = parent.Window;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            _concurrentWindowCollection.Add(windowInformation);

            window.Closing         += WindowClosingCallback;
            window.Closed          += WindowClosedCallback;
            window.Activated       += WindowActivateCallback;
            window.Deactivated     += WindowDeactivatedCallback;
            window.SizeChanged     += WindowSizeChangedCallback;
            window.LocationChanged += WindowLocationChangedCallback;

            return(window);
        }
Exemplo n.º 5
0
        public void TryFocusWindowByWindowKey(WindowKey key)
        {
            var windowToFocus = _concurrentWindowCollection.Get(key);

            if (!ReferenceEquals(windowToFocus, null))
            {
                var window = windowToFocus.Window;

                if (!window.IsVisible)
                {
                    window.Show();
                }
                else
                {
                    window.Activate();
                }
            }
        }
Exemplo n.º 6
0
        public void OpenOrFocusWindow <T>(object key, NavigationParameters parameters = null, Action <IResultDataCollection> onWindowClosedAction = null) where T : Window
        {
            var windowKey     = new WindowKey(typeof(T), key);
            var windowToFocus = _concurrentWindowCollection.Get(windowKey);

            if (!ReferenceEquals(windowToFocus, null))
            {
                // Window already exists
                windowToFocus.Window.Activate();
                return;
            }

            var window = CreateWindow(typeof(T), windowKey, onWindowClosedAction, null, null);

            NavigateInWindow(window, parameters);

            window.Show();
        }
Exemplo n.º 7
0
        public void OpenNewWindowAsDialog <T>(object parent, NavigationParameters parameters = null, Action <IResultDataCollection> onWindowClosedAction = null) where T : Window
        {
            var windowKey       = new WindowKey(typeof(T), Guid.NewGuid());
            var parentWindowKey = FindWindowKeyContainingViewOrViewModel(parent);
            var parentWindow    = _concurrentWindowCollection.Get(parentWindowKey);

            if (ReferenceEquals(parentWindow, null))
            {
                return;
            }

            var window = CreateWindow(typeof(T), windowKey, onWindowClosedAction, null, null);

            NavigateInWindow(window, parameters);

            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.Owner = parentWindow.Window;

            window.Show();
        }
Exemplo n.º 8
0
        public void Open(string viewType, object key, NavigationParameters parameters = null, Action <IResultDataCollection> onWindowClosedAction = null)
        {
            var shellType = _shellInformationService.GetShellType();
            var windowKey = new WindowKey(viewType, key);

            var existingWindow = _concurrentWindowCollection.Get(windowKey);

            if (!ReferenceEquals(existingWindow, null))
            {
                existingWindow.Window.Activate();
                return;
            }

            var regionManager = _regionManager.CreateRegionManager();
            var window        = CreateWindow(shellType, windowKey, onWindowClosedAction, null, regionManager);

            regionManager.RequestNavigate(RegionNames.MainRegion, viewType, parameters);

            window.Show();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Restores the state of the specified window.
        /// </summary>
        /// <param name="key">The window key that identifies the configuration settings</param>
        /// <param name="window">The window instance being restored.</param>
        public void RestoreWindow(WindowKey key, Window window)
        {
            if (window != null && windowConfig.TryGetValue(key, out WindowConfig config))
            {
                window.MinWidth              = windowConfig[key].MinWidth;
                window.MinHeight             = windowConfig[key].MinHeight;
                window.WindowState           = (WindowState)GetItem((int)WindowState.Normal, config.GetPropertyId(WindowConfig.Property.State));
                window.Width                 = GetItem(windowConfig[key].DefaultWidth, config.GetPropertyId(WindowConfig.Property.Width));
                window.Height                = GetItem(windowConfig[key].DefaultHeight, config.GetPropertyId(WindowConfig.Property.Height));
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                /* default values are int.MaxValue which will only be present on first run. */
                int left = GetItem(int.MaxValue, config.GetPropertyId(WindowConfig.Property.Left));
                int top  = GetItem(int.MaxValue, config.GetPropertyId(WindowConfig.Property.Top));
                if (left != int.MaxValue && top != int.MaxValue)
                {
                    window.Left = left;
                    window.Top  = top;
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                }
            }
        }
Exemplo n.º 10
0
        public void OpenDialog(object parent, string viewType, NavigationParameters parameters = null, Action <IResultDataCollection> onWindowClosedAction = null)
        {
            var parentWindowKey  = FindWindowKeyContainingViewOrViewModel(parent);
            var parentWindowInfo = _concurrentWindowCollection.Get(parentWindowKey);

            if (ReferenceEquals(parentWindowInfo, null))
            {
                return;
            }

            var shellType     = _shellInformationService.GetShellType();
            var regionManager = _regionManager.CreateRegionManager();
            var windowKey     = new WindowKey(viewType, Guid.NewGuid());
            var window        = CreateWindow(shellType, windowKey, onWindowClosedAction, parentWindowKey, regionManager);

            regionManager.RequestNavigate(RegionNames.MainRegion, viewType, parameters);

            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.Owner = parentWindowInfo.Window;

            BlockWindow(parentWindowKey);

            window.Show();
        }
Exemplo n.º 11
0
 private static void RegisterWindow(WindowKey windowKey, Type windowType, Type viewModelType)
 {
     AllWindows.Add(windowKey, new RegisteredWindow(windowKey, windowType, viewModelType));
 }
Exemplo n.º 12
0
 public RegisteredWindow(WindowKey windowKey, Type windowType, Type viewModelType)
 {
     WindowKey     = windowKey;
     WindowType    = windowType;
     ViewModelType = viewModelType;
 }
Exemplo n.º 13
0
        public void TryFocusWindow <T>(object key) where T : Window
        {
            var windowKey = new WindowKey(typeof(T), key);

            TryFocusWindowByWindowKey(windowKey);
        }