示例#1
0
        /// <summary>
        /// Applies the specified windowStateEx to the window.
        /// </summary>
        /// <param name="windowStateEx">The WindowStateEx to apply.</param>
        private void Apply(WindowStateEx windowStateEx)
        {
            // If it is already applied.
            if (_appliedWindowStateEx == windowStateEx)
            {
                return;
            }

            // Whether the StateExChanged event is raised or not.
            // If it is the initialization, it should not raise the StateExChanged event. (StateChanged is not raised too.)
            bool isRequiredToRaiseStateExChanged = _appliedWindowStateEx != null;

            // Sets the applied WindowStateEx.
            WindowStateEx oldWindowStateEx = _appliedWindowStateEx ?? WindowStateEx.Normal;

            _appliedWindowStateEx = windowStateEx;

            // Sets the IsFullScreenMode to true if the WindowStateEx is FullScreen.
            switch (windowStateEx)
            {
            case WindowStateEx.Normal:
            case WindowStateEx.Maximized:
                IsFullScreenMode = false;
                break;

            case WindowStateEx.FullScreen:
                IsFullScreenMode = true;
                break;
            }

            // Sets the WindowStateEx.
            WindowStateEx = windowStateEx;

            // Sets the WindowState.
            WindowState = windowStateEx.ToWindowState();

            // If it is Maximized -> Full Screen or Full Screen -> Maximized, hides and shows the window to corrent the size.
            if ((oldWindowStateEx == WindowStateEx.Maximized && windowStateEx == WindowStateEx.FullScreen) ||
                (oldWindowStateEx == WindowStateEx.FullScreen && windowStateEx == WindowStateEx.Maximized))
            {
                Visibility = Visibility.Collapsed;
                Visibility = Visibility.Visible;
            }

            // Updates the WindowStateEx relate properties.
            IsMinimized  = WindowStateEx == WindowStateEx.Minimized;
            IsNormal     = WindowStateEx == WindowStateEx.Normal;
            IsMaximized  = WindowStateEx == WindowStateEx.Maximized;
            IsFullScreen = WindowStateEx == WindowStateEx.FullScreen;

            // If it is required to raise the StateExChanged event
            if (isRequiredToRaiseStateExChanged)
            {
                // Raises the StateExChanged event.
                OnStateExChanged(new CustomWindowStateExChangedEventArgs(oldWindowStateEx, windowStateEx));

                // It is required to update UI that binds to CustomWindow's commands.
                CommandManager.InvalidateRequerySuggested();
            }
        }
示例#2
0
        /// <summary>
        /// Converts a WindowStateEx enumeration to a WindowState enumeration.
        /// </summary>
        /// <param name="windowStateEx">A WindowStateEx.</param>
        /// <returns>The converted  WindowState.</returns>
        public static WindowState ToWindowState(this WindowStateEx windowStateEx)
        {
            switch (windowStateEx)
            {
            case WindowStateEx.Normal:
                return(WindowState.Normal);

            case WindowStateEx.Minimized:
                return(WindowState.Minimized);

            case WindowStateEx.Maximized:
            case WindowStateEx.FullScreen:
                return(WindowState.Maximized);
            }

            throw new InvalidOperationException(string.Format("The WindowStateEx {0} is unknown.", windowStateEx));
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the StateExChangedEventArgs class.
 /// </summary>
 /// <param name="oldValue">The WindowStateEx before the change.</param>
 /// <param name="newValue">The WindowStateEx after the change.</param>
 internal CustomWindowStateExChangedEventArgs(WindowStateEx oldValue, WindowStateEx newValue)
 {
     OldValue = oldValue;
     NewValue = newValue;
 }