예제 #1
0
        /// <summary>
        /// Dependency property event once the windows state value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiChild     mdiChild     = (MdiChild)sender;
            MdiContainer mdiContainer = mdiChild.Container;

            WindowState previousWindowState = (WindowState)e.OldValue;
            WindowState windowState         = (WindowState)e.NewValue;

            if (mdiChild.Container == null ||
                previousWindowState == windowState)
            {
                return;
            }

            if (previousWindowState == WindowState.Maximized)
            {
                if (mdiContainer.ActiveMdiChild.WindowState != WindowState.Maximized)
                {
                    for (int i = 0; i < mdiContainer.Children.Count; i++)
                    {
                        if (mdiContainer.Children[i] != mdiChild &&
                            mdiContainer.Children[i].WindowState == WindowState.Maximized &&
                            mdiContainer.Children[i].MaximizeBox)
                        {
                            mdiContainer.Children[i].WindowState = WindowState.Normal;
                        }
                    }

                    ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                    sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                    sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                }

                mdiChild.Buttons.Children.Clear();
                mdiChild.Buttons = null;
                mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);
            }

            if (previousWindowState == WindowState.Minimized)
            {
                mdiChild.minimizedPosition = mdiChild.Position;
            }

            switch (windowState)
            {
            case WindowState.Normal:
            {
                mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);
                mdiChild.Width    = mdiChild.originalDimension.Width;
                mdiChild.Height   = mdiChild.originalDimension.Height;
            }
            break;

            case WindowState.Minimized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                double newLeft, newTop;
                if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)
                {
                    newLeft = mdiChild.minimizedPosition.X;
                    newTop  = mdiChild.minimizedPosition.Y;
                }
                else
                {
                    List <Rect> minimizedWindows = new List <Rect>();
                    for (int i = 0; i < mdiContainer.Children.Count; i++)
                    {
                        MdiChild child = mdiContainer.Children[i];
                        if (child != mdiChild &&
                            child.WindowState == WindowState.Minimized)
                        {
                            minimizedWindows.Add(new Rect(child.Position.X, mdiContainer.InnerHeight - child.Position.Y, child.Width, child.Height));
                        }
                    }
                    Rect newWindowPlace;
                    bool occupied = true;
                    int  count    = 0,
                         capacity = Convert.ToInt32(mdiContainer.ActualWidth) / MdiChild.MinimizedWidth;
                    do
                    {
                        int row = count / capacity + 1,
                            col = count % capacity;
                        newTop  = MdiChild.MinimizedHeight * row;
                        newLeft = MdiChild.MinimizedWidth * col;

                        newWindowPlace = new Rect(newLeft, newTop, MdiChild.MinimizedWidth, MdiChild.MinimizedHeight);
                        occupied       = false;
                        foreach (Rect rect in minimizedWindows)
                        {
                            Rect intersection = rect;
                            intersection.Intersect(newWindowPlace);
                            if (intersection != Rect.Empty && intersection.Width > 0 && intersection.Height > 0)
                            {
                                occupied = true;
                                break;
                            }
                        }
                        count++;

                        // TODO: handle negative Canvas coordinates somehow.
                        if (newTop < 0)
                        {
                            // ugly workaround for now.
                            newTop   = 0;
                            occupied = false;
                        }
                    } while (occupied);

                    newTop = mdiContainer.InnerHeight - newTop;
                }

                mdiChild.Position = new Point(newLeft, newTop);

                mdiChild.Width  = MdiChild.MinimizedWidth;
                mdiChild.Height = MdiChild.MinimizedHeight;
            }
            break;

            case WindowState.Maximized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }
                mdiChild.NonMaximizedState = previousWindowState;

                mdiChild.buttonsPanel.Children.Clear();
                StackPanel sp = new StackPanel
                {
                    Orientation = Orientation.Horizontal
                };
                sp.Children.Add(mdiChild.minimizeButton);
                sp.Children.Add(mdiChild.maximizeButton);
                sp.Children.Add(mdiChild.closeButton);
                mdiChild.Buttons = sp;

                mdiChild.Position = new Point(0, 0);
                mdiChild.Width    = mdiContainer.ActualWidth;
                mdiChild.Height   = mdiContainer.InnerHeight - 2;       // ContentBorder.BorderThickness="1" in template

                ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;
            }
            break;
            }
            if (mdiContainer.ActiveMdiChild == mdiChild)
            {
                mdiContainer.Buttons = mdiChild.Buttons;
            }
            mdiContainer.InvalidateSize();
        }
예제 #2
0
        /// <summary>
        /// Dependency property event once the MDI layout value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void MdiLayoutValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;
            MdiLayout    value        = (MdiLayout)e.NewValue;

            if (value == MdiLayout.ArrangeIcons ||
                mdiContainer.Children.Count < 1)
            {
                return;
            }

            // 1. WindowState.Maximized -> WindowState.Normal
            List <MdiChild> minimizedWindows = new List <MdiChild>(),
                            normalWindows    = new List <MdiChild>();

            foreach (MdiChild mdiChild in mdiContainer.Children)
            {
                switch (mdiChild.WindowState)
                {
                case WindowState.Minimized:
                    minimizedWindows.Add(mdiChild);
                    break;

                case WindowState.Maximized:
                    mdiChild.WindowState = WindowState.Normal;
                    normalWindows.Add(mdiChild);
                    break;

                default:
                    normalWindows.Add(mdiChild);
                    break;
                }
            }

            minimizedWindows.Sort(new MdiChildComparer());
            normalWindows.Sort(new MdiChildComparer());

            // 2. Arrange minimized windows
            double containerHeight = mdiContainer.InnerHeight;

            for (int i = 0; i < minimizedWindows.Count; i++)
            {
                MdiChild mdiChild = minimizedWindows[i];
                int      capacity = Convert.ToInt32(mdiContainer.ActualWidth / MdiChild.MinimizedWidth),
                         row      = i / capacity + 1,
                         col      = i % capacity;
                containerHeight = mdiContainer.InnerHeight - MdiChild.MinimizedHeight * row;
                double newLeft = MdiChild.MinimizedWidth * col;
                mdiChild.Position = new Point(newLeft, containerHeight);
            }

            // 3. Resize & arrange normal windows
            switch (value)
            {
            case MdiLayout.Cascade:
            {
                double newWidth            = mdiContainer.ActualWidth - (int)(mdiContainer.ActualWidth * 0.20); //Width - 20%
                double newHeight           = containerHeight - (int)(containerHeight * 0.30);                   //Height - 30%
                double CurrentWindowOffset = 0;

                foreach (MdiChild mdiChild in normalWindows)
                {
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(CurrentWindowOffset, CurrentWindowOffset);

                    CurrentWindowOffset += WindowOffset;
                    if (CurrentWindowOffset + mdiChild.Width > mdiContainer.ActualWidth)
                    {
                        CurrentWindowOffset = 0;
                    }
                    if (CurrentWindowOffset + mdiChild.Height > containerHeight)
                    {
                        CurrentWindowOffset = 0;
                    }
                }
            }
            break;

            case MdiLayout.TileHorizontal:
            {
                double cols = Math.Sqrt(normalWindows.Count),
                       rows = normalWindows.Count / cols;

                List <double> col_count = new List <double>();                               // windows per column
                for (int i = 0; i < cols; i++)
                {
                    if (normalWindows.Count % cols > cols - i - 1)
                    {
                        col_count.Add(rows + 1);
                    }
                    else
                    {
                        col_count.Add(rows);
                    }
                }

                double newWidth   = mdiContainer.ActualWidth / cols,
                       newHeight  = containerHeight / col_count[0],
                       offsetTop  = 0,
                       offsetLeft = 0;

                double prev_count = 0;
                for (int i = 0, col_index = 0; i < normalWindows.Count; i++)
                {
                    if (i >= prev_count + col_count[col_index])
                    {
                        prev_count += col_count[col_index++];
                        offsetLeft += newWidth;
                        offsetTop   = 0;
                        newHeight   = containerHeight / col_count[col_index];
                    }

                    MdiChild mdiChild = normalWindows[i];
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(offsetLeft, offsetTop);
                    offsetTop        += newHeight;
                }
            }
            break;

            case MdiLayout.TileVertical:
            {
                double rows = Math.Sqrt(normalWindows.Count),
                       cols = normalWindows.Count / rows;

                List <double> col_count = new List <double>();                               // windows per column
                for (int i = 0; i < cols; i++)
                {
                    if (normalWindows.Count % cols > cols - i - 1)
                    {
                        col_count.Add(rows + 1);
                    }
                    else
                    {
                        col_count.Add(rows);
                    }
                }

                double newWidth   = mdiContainer.ActualWidth / cols,
                       newHeight  = containerHeight / col_count[0],
                       offsetTop  = 0,
                       offsetLeft = 0;

                double prev_count = 0;
                for (int i = 0, col_index = 0; i < normalWindows.Count; i++)
                {
                    if (i >= prev_count + col_count[col_index])
                    {
                        prev_count += col_count[col_index++];
                        offsetLeft += newWidth;
                        offsetTop   = 0;
                        newHeight   = containerHeight / col_count[col_index];
                    }

                    MdiChild mdiChild = normalWindows[i];
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(offsetLeft, offsetTop);
                    offsetTop        += newHeight;
                }
            }
            break;
            }
            mdiContainer.InvalidateSize();
            mdiContainer.MdiLayout = MdiLayout.ArrangeIcons;
        }
예제 #3
0
        /// <summary>
        /// Dependency property event once the MDI layout value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void MdiLayoutValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiContainer mdiContainer = (MdiContainer)sender;
            MdiLayout    value        = (MdiLayout)e.NewValue;

            if (value == MdiLayout.ArrangeIcons ||
                mdiContainer.Children.Count < 1)
            {
                return;
            }

            // 1. WindowState.Maximized -> WindowState.Normal
            List <MdiChild> minimizedWindows = new List <MdiChild>(),
                            normalWindows    = new List <MdiChild>();

            foreach (MdiChild mdiChild in mdiContainer.Children)
            {
                switch (mdiChild.WindowState)
                {
                case WindowState.Minimized:
                    minimizedWindows.Add(mdiChild);
                    break;

                case WindowState.Maximized:
                    mdiChild.WindowState = WindowState.Normal;
                    normalWindows.Add(mdiChild);
                    break;

                default:
                    normalWindows.Add(mdiChild);
                    break;
                }
            }

            minimizedWindows.Sort(new MdiChildComparer());
            normalWindows.Sort(new MdiChildComparer());

            // 2. Arrange minimized windows
            double containerHeight = mdiContainer.InnerHeight;

            for (int i = 0; i < minimizedWindows.Count; i++)
            {
                MdiChild mdiChild = minimizedWindows[i];
                int      capacity = Convert.ToInt32(mdiContainer.InnerWidth) / mdiChild.MinimizedWidth,
                         row      = i / capacity + 1,
                         col      = i % capacity;
                containerHeight = mdiContainer.InnerHeight - mdiChild.MinimizedHeight * row;
                double newLeft = mdiChild.MinimizedWidth * col;
                mdiChild.Position = new Point(newLeft, containerHeight);
            }

            // 3. Resize & arrange normal windows
            switch (value)
            {
            case MdiLayout.Cascade:
            {
                double newWidth     = mdiContainer.InnerWidth * 0.58,                             // should be non-linear formula here
                       newHeight    = containerHeight * 0.67,
                       windowOffset = 0;
                foreach (MdiChild mdiChild in normalWindows)
                {
                    if (mdiChild.Resizable)
                    {
                        mdiChild.Width  = newWidth;
                        mdiChild.Height = newHeight;
                    }
                    mdiChild.Position = new Point(windowOffset, windowOffset);

                    windowOffset += WindowOffset;
                    if (windowOffset + mdiChild.Width > mdiContainer.InnerWidth)
                    {
                        windowOffset = 0;
                    }
                    if (windowOffset + mdiChild.Height > containerHeight)
                    {
                        windowOffset = 0;
                    }
                }
            }
            break;

            case MdiLayout.TileHorizontal:
            {
                var _h = mdiContainer.MinimizedAreaHeight;

                int cols = Math.Max((int)Math.Sqrt(normalWindows.Count), 1);
                int rows = normalWindows.Count / cols;

                rows = Math.Min(rows, mdiContainer.MdiLayoutMaxRow);
                cols = (int)Math.Ceiling((double)normalWindows.Count / (double)rows);

                double w = Math.Max(mdiContainer.InnerWidth / cols, 0);
                double h = Math.Max((mdiContainer.InnerHeight - _h) / rows, 0);

                int count = 0;
                foreach (var item in normalWindows)
                {
                    item.Position = new Point((int)(count % cols) * w, (int)(count / cols) * h);
                    if (w == 0 && h == 0)
                    {
                        item.Width  = item.MinimizedWidth;
                        item.Height = item.MinimizedHeight;
                    }
                    else
                    {
                        item.Width  = w;
                        item.Height = h;
                    }
                    count++;
                }
            }
            break;

            case MdiLayout.TileVertical:
            {
                var _h = mdiContainer.MinimizedAreaHeight;

                int rows = Math.Max((int)Math.Sqrt(normalWindows.Count), 1);
                int cols = normalWindows.Count / rows;

                cols = Math.Min(cols, mdiContainer.MdiLayoutMaxCol);
                rows = (int)Math.Ceiling((double)normalWindows.Count / (double)cols);

                double w = Math.Max(mdiContainer.InnerWidth / cols, 0);
                double h = Math.Max((mdiContainer.InnerHeight - _h) / rows, 0);

                int count = 0;
                foreach (var item in normalWindows)
                {
                    item.Position = new Point((int)(count % cols) * w, (int)(count / cols) * h);
                    if (w == 0 && h == 0)
                    {
                        item.Width  = item.MinimizedWidth;
                        item.Height = item.MinimizedHeight;
                    }
                    else
                    {
                        item.Width  = w;
                        item.Height = h;
                    }
                    count++;
                }
            }
            break;
            }
            mdiContainer.InvalidateSize();
            mdiContainer.MdiLayout = MdiLayout.ArrangeIcons;
        }
예제 #4
0
파일: MdiChild.cs 프로젝트: xavl369/UGRS
        /// <summary>
        /// Dependency property event once the windows state value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiChild mdiChild = (MdiChild)sender;

            WindowState previousWindowState = (WindowState)e.OldValue;
            WindowState windowState         = (WindowState)e.NewValue;

            if (mdiChild.Container == null ||
                previousWindowState == windowState)
            {
                return;
            }

            if (previousWindowState == WindowState.Maximized)
            {
                //for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                //{
                //    if (mdiChild.Container.Children[i] != mdiChild &&
                //            mdiChild.Container.Children[i].WindowState == WindowState.Maximized &&
                //            mdiChild.Container.Children[i].MaximizeBox) { }
                //        //mdiChild.Container.Children[i].WindowState = WindowState.Normal;
                //}

                ScrollViewer sv = (ScrollViewer)((Grid)mdiChild.Container.Content).Children[1];
                sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

                //mdiChild.Buttons.Children.Clear();
                //mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                //mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                //mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);
            }

            if (previousWindowState == WindowState.Minimized)
            {
                mdiChild.minimizedPosition = mdiChild.Position;
            }

            switch (windowState)
            {
            case WindowState.Normal:
            {
                mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);

                mdiChild.Width  = mdiChild.originalDimension.Width;
                mdiChild.Height = mdiChild.originalDimension.Height;
            }
            break;

            case WindowState.Minimized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                double newLeft, newTop;
                if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)
                {
                    newLeft = mdiChild.minimizedPosition.X;
                    newTop  = mdiChild.minimizedPosition.Y;
                }
                else
                {
                    #region Simple
                    int minimizedWindows = 0;
                    for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                    {
                        if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                        {
                            minimizedWindows++;
                        }
                    }
                    int capacity = Convert.ToInt32(mdiChild.Container.ActualWidth) / MdiChild.MinimizedWidth,
                        row      = minimizedWindows / capacity + 1,
                        col      = minimizedWindows % capacity;
                    newTop  = mdiChild.Container.InnerHeight - MdiChild.MinimizedHeight * row;
                    newLeft = MdiChild.MinimizedWidth * col;
                    #endregion
                    #region Complex
                    //List<MdiChild> minimizedWindows = new List<MdiChild>();
                    //for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                    //    if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                    //        minimizedWindows.Add(mdiChild.Container.Children[i]);

                    #endregion
                }

                mdiChild.Position = new Point(newLeft, newTop);

                mdiChild.Width  = MdiChild.MinimizedWidth;
                mdiChild.Height = MdiChild.MinimizedHeight;
            }
            break;

            case WindowState.Maximized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                mdiChild.buttonsPanel.Children.Clear();


                mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);


                mdiChild.Position = new Point(0, 0);
                mdiChild.Width    = mdiChild.Container.ActualWidth;
                mdiChild.Height   = mdiChild.Container.InnerHeight - 2;                               // ContentBorder.BorderThickness="1" in template

                if (mdiChild.Container.AllowWindowStateMax)
                {
                    MdiContainer mdiContainer = mdiChild.Container;
                    mdiContainer.AllowWindowStateMax = false;

                    //for (int i = 0; i < mdiContainer.Children.Count; i++)
                    //    if (mdiContainer.Children[i] != mdiChild)
                    //    {
                    //        if (mdiContainer.Children[i].WindowState == WindowState.Normal &&
                    //            mdiContainer.Children[i].MaximizeBox)
                    //            mdiContainer.Children[i].WindowState = WindowState.Maximized;
                    //        else if (mdiContainer.Children[i].WindowState == WindowState.Maximized)
                    //            mdiContainer.Children[i].Height = mdiContainer.InnerHeight;
                    //    }

                    ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                    sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                    sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;

                    mdiChild.Focus();
                    mdiContainer.InvalidateSize();
                    mdiContainer.AllowWindowStateMax = true;
                }
            }
            break;
            }
        }
예제 #5
0
        /// <summary>
        /// Dependency property event once the windows state value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiChild mdiChild = (MdiChild)sender;

            WindowState previousWindowState = (WindowState)e.OldValue;
            WindowState windowState         = (WindowState)e.NewValue;

            if (mdiChild.Container == null ||
                previousWindowState == windowState)
            {
                return;
            }

            if (previousWindowState == WindowState.Maximized)
            {
                for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                {
                    if (mdiChild.Container.Children[i] != mdiChild &&
                        mdiChild.Container.Children[i].WindowState == WindowState.Maximized &&
                        mdiChild.Container.Children[i].MaximizeBox)
                    {
                        mdiChild.Container.Children[i].WindowState = WindowState.Normal;
                    }
                }

                ScrollViewer sv = (ScrollViewer)((Grid)mdiChild.Container.Content).Children[1];
                sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

                if (mdiChild.Buttons != null)
                {
                    mdiChild.Buttons.Children.Clear();
                }
                try
                {
                    mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                    mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                    mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);
                }
                catch { }
            }

            if (previousWindowState == WindowState.Minimized)
            {
                mdiChild.minimizedPosition = mdiChild.Position;
            }

            switch (windowState)
            {
            case WindowState.Normal:
            {
                mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);

                if (mdiChild._minimizedWidth > 0 && mdiChild._minimizedHeight > 0)
                {
                    mdiChild.MinWidth  = mdiChild._minimizedWidth;
                    mdiChild.MinHeight = mdiChild._minimizedHeight;
                }

                mdiChild.Width  = mdiChild.originalDimension.Width;
                mdiChild.Height = mdiChild.originalDimension.Height;
            }
            break;

            case WindowState.Minimized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                //double newLeft, newTop;
                //if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)
                //{
                //    newLeft = mdiChild.minimizedPosition.X;
                //    newTop = mdiChild.minimizedPosition.Y;
                //}
                //else
                //{
                //    int minimizedWindows = 0;
                //    for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                //        if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                //            minimizedWindows++;
                //    int capacity = Convert.ToInt32(mdiChild.Container.InnerWidth) / mdiChild.MinimizedWidth,
                //        row = minimizedWindows / capacity + 1,
                //        col = minimizedWindows % capacity;
                //    newTop = mdiChild.Container.InnerHeight - mdiChild.MinimizedHeight * row;
                //    newLeft = mdiChild.MinimizedWidth * col;
                //}

                //mdiChild.Position = new Point(newLeft, newTop);

                int minimizedWindows = 0;
                for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                {
                    if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                    {
                        minimizedWindows++;
                    }
                }
                int cols  = (int)(mdiChild.Container.InnerWidth / mdiChild.MinimizedWidth);
                int count = 0;
                foreach (var item in mdiChild.Container.Children)
                {
                    if (item.WindowState == WindowState.Minimized)
                    {
                        item.Position = new Point((int)(count % cols) * item.MinimizedWidth, mdiChild.Container.InnerHeight - ((int)((int)(count / cols) + 1)) * item.MinimizedHeight);
                        count++;
                    }
                }

                mdiChild._minimizedWidth  = (int)mdiChild.MinWidth;
                mdiChild._minimizedHeight = (int)mdiChild.MinHeight;

                mdiChild.MinWidth  = mdiChild.MinimizedWidth;
                mdiChild.MinHeight = mdiChild.MinimizedHeight;

                mdiChild.Width  = mdiChild.MinimizedWidth;
                mdiChild.Height = mdiChild.MinimizedHeight;
            }
            break;

            case WindowState.Maximized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                try
                {
                    StackPanel sp = new StackPanel {
                        Orientation = Orientation.Horizontal
                    };
                    mdiChild.Buttons = sp;
                    if (mdiChild.Container.Theme != ThemeType.Metro)
                    {
                        if (mdiChild.buttonsPanel != null)
                        {
                            mdiChild.buttonsPanel.Children.Clear();
                        }
                        sp.Children.Add(mdiChild.minimizeButton);
                        sp.Children.Add(mdiChild.maximizeButton);
                        sp.Children.Add(mdiChild.closeButton);
                    }
                }
                catch { }

                mdiChild.Position = new Point(0, 0);

                if (mdiChild._minimizedWidth > 0 && mdiChild._minimizedHeight > 0)
                {
                    mdiChild.MinWidth  = mdiChild._minimizedWidth;
                    mdiChild.MinHeight = mdiChild._minimizedHeight;
                }

                mdiChild.Width  = mdiChild.Container.InnerWidth;
                mdiChild.Height = mdiChild.Container.InnerHeight;

                if (mdiChild.Container.AllowWindowStateMax)
                {
                    MdiContainer mdiContainer = mdiChild.Container;
                    mdiContainer.AllowWindowStateMax = false;

                    for (int i = 0; i < mdiContainer.Children.Count; i++)
                    {
                        if (mdiContainer.Children[i] != mdiChild)
                        {
                            if (mdiContainer.Children[i].WindowState == WindowState.Normal &&
                                mdiContainer.Children[i].MaximizeBox)
                            {
                                mdiContainer.Children[i].WindowState = WindowState.Maximized;
                            }
                            else if (mdiContainer.Children[i].WindowState == WindowState.Maximized)
                            {
                                mdiContainer.Children[i].Height = mdiContainer.InnerHeight;
                            }
                        }
                    }

                    ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                    sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                    sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;

                    mdiChild.Focus();
                    mdiContainer.InvalidateSize();
                    mdiContainer.AllowWindowStateMax = true;
                }
            }
            break;
            }
            mdiChild.RaiseEvent(new RoutedEventArgs(WindowStateChangedEvent));
        }