【问题标题】:Why CoreApplicationViewTitleBar.SystemOverlayRightInset is 0 in UWP?为什么 CoreApplicationViewTitleBar.SystemOverlayRightInset 在 UWP 中为 0?
【发布时间】:2022-07-19 21:37:39
【问题描述】:

为什么 SystemOverlayRightInset 是 0 ?在右侧,有字幕按钮(最小化,最大化,关闭)。但它返回0。

我的代码:

public MainPage()
 {
    this.InitializeComponent();
    CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
    coreTitleBar.ExtendViewIntoTitleBar = true;
    double right = coreTitleBar.SystemOverlayRightInset;
  }

我需要 CustomTitleBar ,所以我设置 (coreTitleBar.ExtendViewIntoTitleBar = true) 。基于系统保留的 SystemOverlyRightInset ,我需要在我的自定义区域中放置按钮。但是这里的 SystemOverlayRightInset 值是 0 ?为什么?

【问题讨论】:

  • 与元素的FlowDirection有关
  • 这里 SystemOverlayLeftInset 和 SystemOverlayRightInset 都为零。为什么?
  • 我用官方代码样例测试过,SystemOverlayRightInset 不为零,可以分享一个minimal reproducible example给我们吗?
  • 我的完整代码drive.google.com/drive/folders/…。我没有写太多代码。只是我尝试设置 ExtendViewIntoTitleBar = true 然后尝试获取 RightInset !但它为零?
  • 我检查了你的代码,你只是将ExtendViewIntoTitleBar设置为true,但你没有设置标题栏内容。

标签: c# uwp uwp-xaml


【解决方案1】:

你需要在标题栏的LayoutMetrics变化上注册,像这样-

public MainPage()
{
      this.InitializeComponent();
      CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
      coreTitleBar.ExtendViewIntoTitleBar = true;
      coreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;
 }
 
 private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar coreTitleBar, object args)
 {
      var height = coreTitleBar.Height;
      var right = coreTitleBar.SystemOverlayRightInset;
      var left = coreTitleBar.SystemOverlayLeftInset;
 }

【讨论】:

    猜你喜欢
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多