Tina Debove Nigro

How to compute the TitleBar height on Windows 10

How to compute the TitleBar height on Windows 10

You may need to customize your ApplicationViewTitleBar in your Universal Windows Platform app.

On “normal” screens the TitleBar height is set to 32px, however this may not work on High-DPI screens like the Surface Pro 3. You need to guess the height by yourself.

Updated

Long story short, what’s shown below doesn’t work. At all. The only (dirty) hack that I managed to do is:

  1. Save the original Window.Current.Bounds.Height
  2. Set TitleBar.ExtendViewIntoTitleBar = true
  3. See the new Window.Current.Bounds.Height
  4. Do the maths, the difference is the size of the TitleBar

Here’s how it looks here

var heightOriginal = Window.Current.Bounds.Height;
Window.Current.SizeChanged += (sender, e) =>
{
    var heightNew = Window.Current.Bounds.Height;
    TitleBarHeight = heightNew - heightOriginal;
};
titleBarInstance.ExtendViewIntoTitleBar = extend;

***

Original blogpost

Here’s what I did:

static double ComputeTitleBarHeight()
{
    return Math.Floor(32 * (DisplayInformation.GetForCurrentView().LogicalDpi / 100));
}

Also, you’ll notice that the DPI of your window changes when you move it from your Surface Pro 3 screen to your 22”, Full HD screen. You need to register for the DpiChanged event:

DisplayInformation.GetForCurrentView().DpiChanged += AppViewHelper_DpiChanged;
private static void AppViewHelper_DpiChanged(DisplayInformation sender, object args)
{
    TitleBarHeight = ComputeTitleBarHeight();
}

Someone on Twitter suggested another way, feel free to test it and leave your results by leaving a comment!

Have fun!

How to compute the TitleBar height on Windows 10
Prev post

Multiple Windows in a WinRT app (8.1 and 10)

Next post

VLC 1.5 - On the Road to Windows 10

How to compute the TitleBar height on Windows 10

Get in touch