Setting the native Window the RadWindow appears in on Silverlight 5

11 posts, 1 answers
  1. I
    I avatar
    2 posts
    Member since:
    Mar 2011

    Posted 03 Feb 2012 Link to this post

    In the existing Telerik RadControls there is no way to programmatically set the window a RadWindow appears in. They always appear in the Main Window. This is an issue for Silverlight 5 Out-of-Browser (OOB) applications making use of multiple windows.

    Please introduce a SetWindow function on WindowBase so that the Window the RadWindow appears in can be set. As per the new Silverlight 5 Popup.SetWindow instance method.

    For example the following should be possible:

    var rw = new RadWindow();
    rw.SetWindow(Window.GetWindow(this));
    rw.Content = new TextBlock { Text = "My Content" };
    rw.ShowDialog();

    The value passed to the SetWindow function should be used to determine the RootVisual of the RadWindow using Silverlight 5's new Window.GetWindow static method. It should also be used to set the window of any Popup controls related to the RadWindow.

    Alternatively at the very least please honour the Owner property in a multi-window environment.

    The following steps describe how this can be achieved against the 2011_3_1220 Silverlight RadControls source:

    Solution: Navigation_SL
    Project: Controls_SL
    Files: WindowBase.cs, WindowHostFactory.cs, MultiplePopupWindowHost.cs

    File: Window/WindowBase.cs

    Add a window field which defaults to the main window:

    private System.Windows.Window _window = System.Windows.Application.Current.MainWindow;

    Add a public SetWindow method (with comments):

    public void SetWindow(System.Windows.Window window)
    {
        _window = window;
    }

     

    Edit the ShowWindow method to additionally pass the _window field:
    this.host = WindowHostFactory.GetWindowHost(this, _window);


    File:
    Window/InternalWindow/WindowHostFactory.cs

    Edit the GetWindowHost method, adding a windowWindow argument and call CreateHost with it:

    public static IWindowHost GetWindowHost(WindowBase window, System.Windows.Window windowWindow)
    {
           var windowHost = CreateHost(windowWindow);
           windowHost.Setup(window);
           return windowHost;
    }

    Edit the CreateHost method, adding a window argument and use it to construct the MultiplePopupWindowHost instance:

    private static IWindowHost CreateHost(System.Windows.Window window)
     
           return new MultiplePopupWindowHost(window);


    File
    : Window/InternalWindow/MultiplePopupWindowHost.cs

    Add a window field:

    private System.Windows.Window _window;

    Add a constructor to take the window as an argument:

    public MultiplePopupWindowHost(System.Windows.Window window)
    {
        _window = window;
    }

    Edit the GetHostManager method to use the window field:

    protected override PopupHostManagerBase GetHostManager()
           {
                  if (this.manager == null)
                  {
                         var owner = FindRootOwner(this.DragableWindow);
                // Fix begin
                FrameworkElement root;
                if (owner == null)
                {
                    root = _window.Content;
                }
                else
                {
                    root = ApplicationHelper.GetRootVisual(owner);
                }
                // Fix end
                //var root = ApplicationHelper.GetRootVisual(owner);
                this.manager = new PopupHostManager(root);
                  }
     
                  return this.manager;
           }

    Edit the constructor to call SetWindow on the popup:

    public PopupHostManager(FrameworkElement root)
           : base(root)
    {
           this.popup = new System.Windows.Controls.Primitives.Popup
           {
                 Child = this.Host = new Canvas()
           };
          this.popup.SetWindow(Window.GetWindow(root));
     
           if (root == null)
           {
                 this.popup.Opened += this.OnPopupOpened;
           }
     
           this.popup.IsOpen = true;
    }

    File: Window/RadWindow.cs

    When the Owner property value is set so should the window be set:

    private ContentControl _owner = null;
    /// <summary>
    /// Gets or sets the Owner of the RadWindow.This is a dependency property.ull
    /// </summary>
    public ContentControl Owner
    {
       get { return _owner; }
       set
       {
          _owner = value;
          this.SetWindow(Window.GetWindow(_owner) ?? Application.Current.MainWindow);
       }
    }

    File: Window/InternalWindow/BrowserWindowPresenter.cs 
    Method: UpdateStartupLocation

    Finally with multiple windows now supported the behaviour of the WindowStartupLocation property when set to CenterScreen needs to be defined. I suggest that it defaults to the center of it's owner's window (rather than appear in a secondary window with the center position from the main window), i.e.:

                if (centerScreen)
                {
    #if SILVERLIGHT
                var window = Window.GetWindow(this);
                var plugin =
                    window == null
                    ? Application.Current.MainWindow.Content as FrameworkElement
                    : window.Content;
                var size =
                    new Size(plugin.ActualWidth / ApplicationHelper.ZoomFactor,
                             plugin.ActualHeight / ApplicationHelper.ZoomFactor);
    #else
                    var size = ApplicationHelper.ApplicationSize;
    #endif
     
                    location.X = Math.Floor((size.Width - presenterSize.Width) / 2);
                    location.Y = Math.Floor((size.Height - presenterSize.Height) / 2);
     
                    this.UpdatePresenterPosition(location.X, location.Y);
                }

  2. Answer
    Boyan
    Admin
    Boyan avatar
    758 posts
    Member since:
    Apr 2013

    Posted 09 Feb 2012 Link to this post

    Hello,

    We are aware of this problem. Unfortunately the fix for this issue will not make it for Q1 which is scheduled for next week, but we will make sure that it will be fixed in one of the internal builds after that and will be included in the service pack. I have logged it in our PITS as issue 9680, so you can follow its progress.

    Thank you for the detailed explanation and the code. We have added points to your account for the suggestion. Don't hesitate to contact us if you have other questions.

    Regards,
    Boyan
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

  3. DevCraft Release
  4. Grant
    Grant avatar
    11 posts
    Member since:
    Oct 2011

    Posted 02 Jul 2012 Link to this post

    Is there any plan to fix or add this functionality? It is very important for our application to leverage SL5 native windows in OOB mode to support multiple monitors. 

  5. Boyan
    Admin
    Boyan avatar
    758 posts
    Member since:
    Apr 2013

    Posted 05 Jul 2012 Link to this post

    Hi Grant,

    Implementing this functionality was delayed due to more urgent tasks and I am afraid that it is not scheduled for next Q as well. At this moment we can't give you an exact timeframe when support for this functionality will be implemented.

    We are sorry for the inconvenience, don't hesitate to contact us if you have other questions.


    Regards,
    Boyan
    the Telerik team

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

  6. Simon
    Simon avatar
    3 posts
    Member since:
    Oct 2011

    Posted 21 May 2013 Link to this post

    Is there any workaround for this or updated information on when it might be fixed?

  7. Vladi
    Admin
    Vladi avatar
    664 posts
    Member since:
    Jun 2012

    Posted 27 May 2013 Link to this post

    Hello,

    As the tasks for our next Q are not fully planed we will consider adding this to our time schedule, unfortunately as this is a case specific issue and we have other tasks with bigger priority we cannot confirm that it would be included in the tasks for the next Q release of RadControls.

    We will continue to track the demand for this functionality and do our best to implement it in one of our future versions of RadWindow. Again we apologize for any inconvenience that this maybe causing.

    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Andrew
    Andrew avatar
    4 posts
    Member since:
    Jul 2012

    Posted 28 Apr Link to this post

    Has this not been resolved?  I have a SL web app which pops up a RadWindow dialog for entry, and if there are errors, pops up a second  RadWindow alert.  I have set the owner of the second window to be the first, but it still appears behind (preventing the user from selecting the OK button and forcing a page refresh to continue).

  9. Vladi
    Admin
    Vladi avatar
    664 posts
    Member since:
    Jun 2012

    Posted 29 Apr Link to this post

    Hi Andrew,

    We are not sure what exactly the issue is that you are experiencing.

    From what we understand you have a RadWindow opened with the use of the ShowDialog() method and after that another RadWindow is opened from that initial window with the Show() method. In that scenario if the Owner of the second RadWindow is set to be the first one, the second window will always be on top of its parent. This is valid for both OOB and normal Silverlight applications. The previously mentioned issue is related to the possibility of opening RadWindow instances when in OOB application out of the MainPage of the application which is currently not supported in the RadWindow control. This feature request has been logged in our feedback portal and you can vote of it and track its status here.

    I created and attached a sample project for you showing how the second RadWindow is correctly placed above its parent. If we have missed something please let us know.

    Regards,
    Vladi
    Telerik

     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     

  10. Andrew
    Andrew avatar
    4 posts
    Member since:
    Jul 2012

    Posted 29 Apr in reply to Vladi Link to this post

    Vladi-
    Thanks for your reply.  I was setting the Owner properly, but was caught by the first window having 'IsTopmost' set to true.  After I removed that setting, the behavior was as expected.
    Andrew

  11. Sébastien
    Sébastien avatar
    1 posts
    Member since:
    Oct 2013

    Posted 11 Jul Link to this post

    Any update on this issue ? (to me this is more a bug than a feature... Steps to workaround have been published long time ago...)

    Thanks for your reply.

  12. Kalin
    Admin
    Kalin avatar
    767 posts
    Member since:
    May 2013

    Posted 14 Jul Link to this post

    Hello Sébastien,

    I understand your concern. However this Feature Request is not planed for implementation yet. What I can suggest you would be to follow the item in our Feedback portal (you can vote as well if you haven't done it yet). This way you will get notified as soon as its status is changed.

    Hope this helps.

    Regards,
    Kalin
    Telerik

     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     

Back to Top
DevCraft Release