RadWindow TopOffset in 2011 Q2?

5 posts, 0 answers
  1. Vasile
    Vasile avatar
    33 posts
    Member since:
    Dec 2010

    Posted 28 Jul 2011 Link to this post

    Hello,

    I just installed the 2011 Q2, and I have observed that the TopOffset & LeftOffset are no longer present in the RadWindow control.

    I used it to move little bit up the window positioned by default with CenterOwner, when the owner window is very large a small window (e.g. Login) does not look very nice on the middle - verticlaly, I want it little bit on the top side, in the previous releases I did that by using a TopOffset = -100 combined with CenterOwner, it was exactly what I needed.

    Could you suggest an alternative method of achieving this?

    Thanks,
    Vasile
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 29 Jul 2011 Link to this post

    Hi Vasile,

    The Offset properties were obsolete for a long time and were removed for that reason. It is strange that you even had them working in a certain scenario.

    You have two options for positioning RadWindow: you can choose to position it with the WindowStartupLocation if you want it centered on the screen; you can use the Top and Left properties to manually find the optimal screen position of the window.

    Please, note that the latter 4 properties cannot be used alongside WindowStartupLocation and vice versa.

    I hope this will give you a clue of the possible options.


    Greetings,
    Dani
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Vasile
    Vasile avatar
    33 posts
    Member since:
    Dec 2010

    Posted 29 Jul 2011 Link to this post

    Well that worked for me, and I appreciate it as being nice and subtile.. now the subtile is gone. I'll do the manual calculations then...

    thanks,
    Vasile

  5. Paul Dhertoghe
    Paul Dhertoghe avatar
    13 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2011 Link to this post

    Dani,

    for the sake of backwards compatibility we cannot understand that these dependency properties were removed. Moreover:
    1. We migrated from Silverlight RadControls 2010 Q3 SP1 and these dependency properties were not marked with the [Obsolete] attribute.
    2. The design was not that awkward nor confusing that it was advisable to delete them. In the code posted below there are some comments that it doesn't work in XBAP scenarios, but you can always throw an exception in that case ("offset properties not supported in XBAP deployments")

    I've spend a fair amount of time figuring out how to perform these calculations. At least you could have updated the documentation so upgrading to a newer version is less painful. An example is "http://www.telerik.com/help/silverlight/radrichtextbox-features-radrichtextboxribbonui.html" (In the versions before 2011.Q3.Beta (2011.3.1020), it was based on RadRibbonBar, but starting from the version in question, it uses the new RadRibbonView instead. The advantages of using the new control compared to the old one are described in detail in this blog post.)

    The previous version of Telerik contained the following code for the calculations:

    using System;
    using System.Windows;

    namespace Telerik.Windows.Controls.RadWindowPopup
    {
     internal abstract class BrowserWindowPopup : WindowPopup
     {
      public override Size GetRootSize()
      {
       return ApplicationHelper.ApplicationSize;
      }

      protected override void OnOpened(EventArgs args)
      {
       base.OnOpened(args);
       if (this.WindowStartupLocation == WindowStartupLocation.CenterOwner ||
        this.WindowStartupLocation == WindowStartupLocation.CenterScreen)
       {
        this.PositionWindow();
       }
      }

      protected override void OpenPopup()
      {
       var owner = this.Owner as RadWindow;
       if (owner != null && !owner.IsOpen)
       {
        throw new InvalidOperationException("Cannot set Owner property to a RadWindow that has not been shown previously.");
       }
      }

      // XXX This won't work for XBAP if in a different window than the main one.
      private void PositionWindow()
      {
       // TODO: Decouple this method from RadWindow class.
       var window = this.Child as RadWindow;
       if (window == null)
       {
        return;
       }

       var rootSize = this.GetRootSize();

       if (rootSize.Width <= 0 || rootSize.Height <= 0)
       {
                    var rootVisual = ApplicationHelper.GetRootVisual(this.Owner);
                    rootVisual.LayoutUpdated += this.OnApplicationLayoutUpdated;
        return;
       }

       if (window.ActualWidth <= 0 || window.ActualHeight <= 0)
       {
        window.LayoutUpdated += this.OnWindowLayoutUpdated;
        return;
       }

       if (this.WindowStartupLocation == WindowStartupLocation.CenterOwner &&
        this.Owner != null &&
        (this.Owner.ActualWidth <= 0 || this.Owner.ActualHeight <= 0))
       {
        this.Owner.LayoutUpdated += this.OnWindowOwnerLayoutUpdated;
        return;
       }

       Point parentStart = new Point(window.LeftOffset, window.TopOffset);
       Size parentSize = this.GetRootSize();

       if (this.WindowStartupLocation == WindowStartupLocation.CenterOwner &&
        this.Owner != null)
       {
        parentStart = this.Owner
         .TransformToVisual(ApplicationHelper.GetRootVisual(this.Owner))
         .Transform(parentStart);

        parentSize = new Size(this.Owner.ActualWidth, this.Owner.ActualHeight);
       }

       Rect parentRect = new Rect(parentStart, parentSize);
       PlacementHelper helper = new PlacementHelper(parentRect,
        new Size(window.ActualWidth, window.ActualHeight),
        0,
        0,
        this.GetRootSize(), window.FlowDirection);

       Point newLocation = helper.GetPlacementOrigin(PlacementMode.Center);

       window.Left = newLocation.X;
       window.Top = newLocation.Y;
       window.UpdateLayout();
      }

      private void OnApplicationLayoutUpdated(object sender, EventArgs e)
      {
                var rootVisual = ApplicationHelper.GetRootVisual(this.Owner);
                if (rootVisual.ActualWidth > 0 && rootVisual.ActualHeight > 0)
                {
                    rootVisual.LayoutUpdated -= this.OnApplicationLayoutUpdated;
                    this.PositionWindow();
                }
      }

      private void OnWindowLayoutUpdated(object sender, EventArgs e)
      {
       var window = this.Child as RadWindow;
       if (window != null)
       {
        if (window.ActualWidth > 0 && window.ActualHeight > 0)
        {
         window.LayoutUpdated -= this.OnWindowLayoutUpdated;
         this.PositionWindow();
        }
       }
      }

      private void OnWindowOwnerLayoutUpdated(object sender, EventArgs e)
      {
       if (this.Owner.ActualWidth > 0 && this.Owner.ActualHeight > 0)
       {
        this.Owner.LayoutUpdated -= this.OnWindowOwnerLayoutUpdated;
        this.PositionWindow();
       }
      }
     }
    }

    Note: one also needs the code for the ApplicationHelper class.
  6. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 21 Dec 2011 Link to this post

    Hi Paul,

    I am sorry to hear about your frustration. We always try to avoid introducing breaking changes, but there are cases when these are needed. We had good reasons for them and I hope you will be able to benefit from the result of the changes, despite the overhead of adjusting your code to them.

    Please accept our apologies for the caused inconvenience.

    Greetings,
    Yana
    the Telerik team

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

Back to Top
DevCraft banner