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.
Thanks Andrew, it helped.
When you drag the window into a floating position the Width/Height are set to explicit values by the dockmanager. If you were to set the Width and Height to NaN in your ToolWindowLoaded handler you should see that it will grow/shrink as you toggle the checkbox because the window doesn't have an explicit size. However once you resize the window it once again has an explicit width and height. This is really no different than if you were to create a regular WPF window and set the SizeToContent to WidthAndHeight. You would see it would adjust its size as you clicked the checkbox but once you resized the window it wouldn't change its size. So you either need to prevent resizing (e.g. set the ResizeMode in the ToolWindowLoaded to NoResize) or you need to get to the ToolWindow when you toggle the checkbox (there is an inherited attached property so you can use something like ToolWindow.GetToolWindow(this) where this is your UserControl) and set the Width/Height again (either to NaN or some explicit value - like trying to increase the height when the checkbox is checked, etc).
Please see attached sample app. Scenario is:1. Run app.2. You should see red and green rectangle in a tab.3. Uncheck "Expanded" checkbox - green rectangle should collapse.4. Undock tab.5. Check "Expanded" checkbox - you should see only red rectangle.6. Now resize height of tool window until you will see green rectangle.7. Now uncheck checkbox - green rectangle is collapsed now but tool window stays the same height to which you've resized it.
What I want to archieve is to make tool window change its height according to the green rectangle visibility.
I'm not sure I understand. You were asking about PaneToolWindow. A PaneToolWindow hosts one or more ContentPane instances - not the xamDockmanager itself. If you're saying that you have a PaneToolWindow that hosts a XamDockManager within a single ContentPane then really this is no different than if you had put a xamDockManager into a Window whose SizeToContent was WidthAndHeight. Maybe you could post a sample that demonstrates the issue so we can understand the exact structure and see what is happening and can tell you whether it will work and if not why.
I got a DocumentContentHost inside XamDocManager with SplitPane inside it. Do I understand correctly that it is not possible get desired auto-size functionality at the moment?