Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Window > Confine RadWindow to region

Answered Confine RadWindow to region

Feed from this thread
  • Enal avatar

    Posted on Oct 7, 2011 (permalink)

    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!

    Reply

  • Answer Miroslav Nedyalkov Miroslav Nedyalkov admin's avatar

    Posted on Oct 10, 2011 (permalink)

    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 >>

    Reply

  • Enal avatar

    Posted on Oct 10, 2011 (permalink)

    Thanks, this approach works well for our purpose.

    Reply

  • Posted on Dec 13, 2011 (permalink)

    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?

    Reply

  • Konstantina Konstantina admin's avatar

    Posted on Dec 16, 2011 (permalink)

    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 >>

    Reply

  • Posted on Jan 26, 2012 (permalink)

    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

    Reply

  • Konstantina Konstantina admin's avatar

    Posted on Jan 31, 2012 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Window > Confine RadWindow to region
Related resources for "Confine RadWindow to region"

Silverlight Window Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]