简体   繁体   English

不一致的标题栏高度返回

[英]Inconsistent TitleBar Height returns

Long story short, I tried to run this particular code长话短说,我试图运行这个特定的代码

CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
dragarea.Height = coreTitleBar.Height;
HamBut.Margin = new Thickness(0, dragarea.Height, 0, 0);
Window.Current.SetTitleBar(dragarea);

When I run it on the first time, coreTitleBar.Height returns 32. But, when I tried to re-run it, It returns 0.当我第一次运行它时, coreTitleBar.Height返回 32。但是,当我尝试重新运行它时,它返回 0。

Is this supposed to be a bug, or am I doing it wrong?这应该是一个错误,还是我做错了?

Currently using Visual Studio 2017 RC.目前使用的是 Visual Studio 2017 RC。

It depends on when the code is run, and yes UWP isn't very consistent about it.这取决于代码何时运行,是的,UWP 对此不太一致。

What the docs don't explicitly mention is that you need to subscribe to the coreTitleBar.LayoutMetricsChanged event and then update the height in the callback. 文档没有明确提到的是您需要订阅coreTitleBar.LayoutMetricsChanged事件,然后在回调中更新高度。 This will account for situations where the size of the title bar changed for some reason.这将说明由于某种原因标题栏的大小发生变化的情况。

coreTitleBar.LayoutMetricsChanged += delegate
{
  dragarea.Height = coreTitleBar.Height;
  HamBut.Margin = new Thickness(0, dragarea.Height, 0, 0);
};

And it also eliminates the "but it's zero sometimes" problem.它还消除了“但有时为零”的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM