Confine RadWindow to region

7 posts, 1 answers
  1. Enal
    Enal avatar
    39 posts
    Member since:
    Oct 2011

    Posted 07 Oct 2011 Link to this post

    Hi - 

    We need a little more control than IsRestricted - we want to define the limiting area.
    i.e. we have a tool area on the left hand side and a 'work' area for windows on the right hand.
    We do not want to cover the tool area with windows. Basically we want to do the following:

    1. Define a left limit in pixels
    2. Moving should be restricted once window.Left reaches the limit.
    3. Maximize window should not expand over the limit.

    Alternatively,defining some sort of container (Grid?) to confine the windows would work as well.

    Any help? Thanks!

  2. Answer
    Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 10 Oct 2011 Link to this post

    Hi Enal,

     What you need is not supported by the RadWindow control - it supports just a property of type Thickness which defines a rectangular region (which in your case could be (left, 0, 0, 0) ) and doesn't affect the maximized state. Though a work-around exist for this limitation. Here is an example:

    private void OnOpenWindowClicked(object sender, RoutedEventArgs e)
    {
        var window = new RadWindow { Content = "Some content", RestrictedAreaMargin = new Thickness(50), IsRestricted = true };
        new WindowRestrictedMaximizedStateBehavior(window);
        window.Show();         
    }
      
    private class WindowRestrictedMaximizedStateBehavior
    {
        private RadWindow window;
      
        public WindowRestrictedMaximizedStateBehavior(RadWindow window)
        {
            this.window = window;
            window.WindowStateChanged += this.window_WindowStateChanged;
        }
      
        private void window_WindowStateChanged(object sender, EventArgs e)
        {
            var window = sender as RadWindow;
            if (window.WindowState == WindowState.Maximized && window.IsRestricted)
            {
                window.Dispatcher.BeginInvoke(UpdateWindowSize);
                var root = Application.Current.RootVisual as FrameworkElement;
                root.SizeChanged += this.root_SizeChanged;
            }
            else
            {
                var root = Application.Current.RootVisual as FrameworkElement;
                root.SizeChanged -= this.root_SizeChanged;
            }
        }
      
        private void root_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.UpdateWindowSize();
        }
      
        private void UpdateWindowSize()
        {
            var root = Application.Current.RootVisual as FrameworkElement;
            var presenter = window.ParentOfType<WindowPresenterBase>();
            presenter.Left = window.RestrictedAreaMargin.Left;
            presenter.Top = window.RestrictedAreaMargin.Top;
            presenter.Width = root.ActualWidth - window.RestrictedAreaMargin.Left - window.RestrictedAreaMargin.Right;
            presenter.Height = root.ActualHeight - window.RestrictedAreaMargin.Top - window.RestrictedAreaMargin.Bottom;
        }
    }

    There is also a way to make more precise way to constraint the dragging and resizing of the RadWindow control, but is more complex to use.

    Hope this helps.

    Best wishes,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Enal
    Enal avatar
    39 posts
    Member since:
    Oct 2011

    Posted 10 Oct 2011 Link to this post

    Thanks, this approach works well for our purpose.
  5. Brian Lam
    Brian Lam avatar
    28 posts
    Member since:
    Apr 2010

    Posted 13 Dec 2011 Link to this post

    Is there a reason that RadWindow no longer uses the RestrictedAreaMargin when it's maximized? It used to respect those values as of the Q1 2011 release, but it doesn't do that anymore in Q3 2011. Is this a feature that's going to be added back in?
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 16 Dec 2011 Link to this post

    Hello Brian,

    This functionality has been changed after the refactoring of the RadWindow. Now, the maximizing of the Window doesn't respect the RestrictedAreaMargin property. We did this change in order to keep the behaviour consistent in WPF and Silverlight. However, a PITS item has been created for returning this behaviour for Silverlight. You can view it here. You can vote for it, track its status and if it receives enough votes we will consider implementing it.

    Hope this information helps.

    Greetings,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  7. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 26 Jan 2012 Link to this post

    Hi,

    Miroslav wrote "There is also a way to make more precise way to constraint the dragging and resizing of the RadWindow control, but is more complex to use." Please, can I have a link or explanation about this more precise way.

    I'd like to implement an MDI style application using RadWindow control. Please, Is there any guide or like about this topic? 

    In addition, I think it would be a good idea that Telerik could offers a built-in MDI container implementation.

    Thanks
  8. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 31 Jan 2012 Link to this post

    Hi Daní,

    The more complex way that Miroslav is refering to is not working entirely correct. However, this is what you have to do:
    1) Hook to the Loaded and SizeChanged events of the page:

    this.Loaded += this.Example_Loaded;  
    ((FrameworkElement)Application.Current.RootVisual).SizeChanged += this.Example_SizeChanged;

    2) In each of them call the following method:

    public void SetRestrictedAreaMarginToRadWindow()
            {
                GeneralTransform generalTransform1 = this.restrictedAreaRectangle.TransformToVisual(Application.Current.RootVisual);
                Point topLeftOffset = generalTransform1.Transform(new Point(0, 0));
                Point bottomRightOffset = generalTransform1.Transform(new Point(this.restrictedAreaRectangle.RenderSize.Width, this.restrictedAreaRectangle.RenderSize.Height));
                  
                double right = ((FrameworkElement)Application.Current.RootVisual).ActualWidth - bottomRightOffset.X;
                double bottom = ((FrameworkElement)Application.Current.RootVisual).ActualHeight - bottomRightOffset.Y;
                  
                window.RestrictedAreaMargin = new Thickness(topLeftOffset.X, topLeftOffset.Y, right, bottom);
            }

    It calculates the size of the page (the Silverlight plug-in) and sets an offset of the RadWindow according to it.
    However, there are some issues, for example when maximizing and restricting the window after that, so please keep in mind that you might come across more.

    Hope this helps.

    Kind regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top
DevCraft banner