src/Foundation/Presentation/Gimela.Presentation.Controls/Controls/MDI/MDIChild.cs
/// <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>
Dependency property event once the windows state value has changed.
Dependency property event once the windows state value has changed .
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
            {
              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;
            }
            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();
            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 = mdiChild.Container.ActualWidth;
            mdiChild.Height = mdiChild.Container.InnerHeight - 2; 
            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;
      }
    }
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 { 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 ; } 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 ( ) ; 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 = mdiChild . Container . ActualWidth ; mdiChild . Height = mdiChild . Container . InnerHeight - 2 ; 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 ; } }
Dependency property event once the windows state value has changed.
Dependency property event once the windows state value has changed .
// ContentBorder.BorderThickness="1" in template
sender
DependencyObject
None
e
DependencyPropertyChangedEventArgs
The  instance containing the event data.
The instance containing the event data .