1

I have child window with Height=300 and Width=400.When i maximize this child window,it gets display on left=0 and top=0 position.I want it to be display in the center of the MainWindow.

I have tried following ways

  • In Window_StateChanged event, i have tried to change its position as left=100 and Top=140.The values are assigned,but still it displays on left=0 and Top=0 position.

  • I also tried to change its position in Window_SizeChanged event,but it also did not work.

  • Then i felt the layout might not refresh,so i refreshed it using this.UpdateLayout(),but not worked.

  • "Maximized" and "Centered" don't usually go together... Are you asking how to keep a control centered in your main window? – bdimag Jul 01 '14 at 18:50
  • I want my child window on same position after maximize.It should increase its size but not position. – user3794868 Jul 02 '14 at 05:27
  • There's some interesting stuff going on in here that I haven't completely figured out: http://stackoverflow.com/questions/2967218/window-out-of-the-screen-when-maximized-using-wpf-shell-integration-library (Microsoft.Windows.Shell is found in NuGet) – bdimag Jul 03 '14 at 13:33

1 Answers1

0

this may be what you're after

    void Window1_StateChanged(object sender, EventArgs e)
    {
        if (this.WindowState == System.Windows.WindowState.Maximized)
        {
            this.WindowState = System.Windows.WindowState.Normal;
            this.Left = (App.Current.MainWindow.Width - this.MaxWidth) / 2 + App.Current.MainWindow.Left;
            this.Top = (App.Current.MainWindow.Height - this.MaxHeight) / 2 + App.Current.MainWindow.Top;
            this.Width = this.MaxWidth;
            this.Height = this.MaxHeight;
        }
    }
bdimag
  • 953
  • 8
  • 11
  • Appreciate your efforts bro,but now doing this,the state of the window becomes normal and i wont be able to "Restore Down". – user3794868 Jul 03 '14 at 06:32