ToolWindow and LocationChanged

3 posts, 0 answers
  1. Neil
    Neil avatar
    10 posts
    Member since:
    Apr 2011

    Posted 08 Aug 2011 Link to this post

    Given a Floating ToolWindow the LocationChanged event doesnt fire when the window is dragged. This is making it impossible to ensure that the windows stay inside the main view as we cannot detect when the position changes to constrain the movement. Any ideas for workarounds?
  2. bg
    bg avatar
    19 posts
    Member since:
    Jul 2006

    Posted 09 Aug 2011 Link to this post

    This broke for me as well in Q2. Here is my workaround.

    During the PaneStateChange Event for the rad docking control attache an event handler for LayoutChangeEnded on the tool window:
    private void radDocking_PaneStateChange(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                foreach (RadPane pane in radDocking.Panes)
                {
                    if (pane != null && pane.IsFloating)
                    {
                        INotifyLayoutChange window = GetToolWindowNLC(pane);
     
                        if (window != null)
                        {
                            window.LayoutChangeEnded += new EventHandler(window_LayoutChangeEnded);
                        }
                    }
                }
            }
    Here is the code for GetToolWindowNLC:
    private INotifyLayoutChange GetToolWindowNLC(RadPane pane)
            {
                ToolWindow window = pane.ParentOfType<ToolWindow>();
     
                if (window == null)
                {
                    return (((pane.Parent as RadPaneGroup).Parent as RadSplitContainer).Parent) as INotifyLayoutChange;
                }
     
                return window as INotifyLayoutChange;
            }

    This will keep the tool window within the bounds of your application:
    void window_LayoutChangeEnded(object sender, EventArgs e)
            {
                ToolWindow window = (ToolWindow)sender;           
     
                if (window.Top < 0)
                {
                    window.Top = 1;
                }
     
                if (window.Left < 0)
                {
                    window.Left = 1;
                }
     
                if (window.Top > this.radDocking.ActualHeight - window.ActualHeight)
                {
                    window.Top = this.radDocking.ActualHeight - window.ActualHeight;
                }
     
                if (window.Left > this.radDocking.ActualWidth - window.ActualWidth)
                {
                    window.Left = this.radDocking.ActualWidth - window.ActualWidth;
                }
            }
    Hope that helps you out. It worked for me.

  3. DevCraft banner
  4. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 11 Aug 2011 Link to this post

    Hello Neil,

    Thank you for your feedback.

    This issue is now fixed and the fix will be available with the next internal build.

    Please do not hesitate to contact us if you require any further information or help.

    Kind regards,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package.
    Get now >>
Back to Top