Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
590
PaneToolWindow with auto size
posted

Hi.

Is there any way to make PaneToolWindow to be dependent on its content resize? I have a user control inside with a expandable section so If it's expanded tool window should increase it's height to show it. I was able to set initial tool window size depending on my user control size using this code but still can't figure out how to handle control size changes:

private void XamDockManager_ToolWindowLoaded(object sender, PaneToolWindowEventArgs e)

{
     var control = FindVisualChildren<MyUserControl>(e.Window.Content as DependencyObject).FirstOrDefault();

     if (control != null)
     {

         e.Window.Height = control.ActualHeight;
         e.Window.Width = control.ActualWidth;

     }

}

I tried to subscribe SizeChanged event in the XamDockManager_ToolWindowLoaded but in it looks like tool window somehow forces its children to resize during startup so I got bunch of SizeChanged with size going to zero. Which leads tool window to be opened with zero size after all.

Parents
  • 54937
    Offline posted

    If the Width and Height of the ToolWindow itself are NaN then it would sort of size to content. I say sort of because it depends on the content. If you have a single pane within the toolwindow then it should work but if you had 2 panes in say a SplitPane then it really won't because the SplitPane won't size the children based on their desired size directly but considers the RelativeSize of the children to determine the ratio used for the size given to the children.

    BTW the snippet you list wouldn't work if the ToolWindow were provided non-client area (i.e. if it contained the elements for the caption and resize edges) which it would in some themes or with some property settings.

Reply Children