views:

425

answers:

2

WPF includes the title bar height in the total window height instead of using only the client content area height.

  • Is there a way to disable this behaviour?
  • If not, how can I get the height of a tool window title bar?

I'm aware of the SystemParameters.CaptionHeight property and the SystemParameters.WindowCaptionHeight property but they both return the height of a regular window title bar. This is not the correct value for a tool window because the title bar is smaller for this type of window. I need something like SystemParameters.ToolWindowCaptionHeight

Thanks.

+1  A: 

You could fall back to System.Windows.Forms.SystemInformation.ToolWindowCaptionHeight. Although it is in the WinForms namespace, it is hardly a WinForms only class.

Lars Truijens
Thanks Lars, works perfect. I'd prefer to avoid adding the Windows Forms reference to my project but this will do until there is a native WPF solution.
+1  A: 

The size of the client area is the actual size of the window's root element :

public double ClientWidth
{
    get { return ((FrameworkElement)this.Content).ActualWidth; }
}

public double ClientHeight
{
    get { return ((FrameworkElement)this.Content).ActualHeight; }
}
Thomas Levesque
This property is useless in my context because it is read only. If there is a way to set the client area size I would be able to achieve what I'm trying to do.
I also need to do all the work before the window is shown and ActualWidth / ActualHeight are not set at that time.