Can't maximize the dialog when using Maxheight and Resizing

2 posts, 0 answers
  1. khai
    khai avatar
    6 posts
    Member since:
    Jan 2011

    Posted 29 Nov 2013 Link to this post

    Hi Telerik,

    I have a problem on using RadWindow. Because its content is loaded on demand so I want it can re-size automatically.
    This below code make the radwindow cant maximize when I click Maximize button.
    Hope your help!
     
    MinHeight="100" MaxHeight="{Binding WindowHeight, Mode=TwoWay}"
    SizeChanged="OnSizeChanged"
    private void OnSizeChanged(object sender, SizeChangedEventArgs e)
            {
                Size appSize = Application.Current.RootVisual.RenderSize;
                Left = Math.Round((appSize.Width / 2) - (ActualWidth / 2), 0);
                Top = Math.Round((appSize.Height / 2) - (ActualHeight / 2), 0);
            }
  2. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 02 Dec 2013 Link to this post

    Hi Khai,

    The reason for the explained behavior is because of the MaxHeight which is affecting the Height of the maximized Window. However what you can do is to reset the MaxHeight in the SizeChanged event handler when the Window is in Maximized state and set it back when it is not. Please check the following code snippet below, I have used a variable to keep the old value:

    private double oldMaxHeight;
    private void RadWindow_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        var window = sender as RadWindow;
     
        if (window.WindowState == System.Windows.WindowState.Maximized)
        {
            if (this.oldMaxHeight == 0)
            {
                this.oldMaxHeight = window.MaxHeight;
                window.MaxHeight = Application.Current.RootVisual.RenderSize.Height;
            }
        }
        else
        {
            if (this.oldMaxHeight != 0)
            {
                window.MaxHeight = this.oldMaxHeight;
                this.oldMaxHeight = 0;
            }
        }
     
        Size appSize = Application.Current.RootVisual.RenderSize;
        Left = Math.Round((appSize.Width / 2) - (ActualWidth / 2), 0);
        Top = Math.Round((appSize.Height / 2) - (ActualHeight / 2), 0);
    }


    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top