Extend buttons to title bar in UWP

纵然是瞬间 提交于 2020-01-04 03:39:09

问题


Is there a simple way to extend window controls into the title bar and make them clickable?

I read the related post (How to customize the application title bar for a UWP page) and I understand how to extend into the title bar area visually. However, my buttons are not clickable in that area (as if there is a layer over them, preventing them from being clicked).


回答1:


Sure thing, you start with

//draw into the title bar
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

//remove the solid-colored backgrounds behind the caption controls and system back button
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

From there, it's going to be a matter of placing a button in the right space.

This will also be helpful since you will be eliminating your app title:

<!-- Page attribute -->
xmlns:appmodel="using:Windows.ApplicationModel"

<TextBlock x:Name="AppTitle" Style="{StaticResource CaptionTextBlockStyle}"
    Text="{x:Bind appmodel:Package.Current.DisplayName}" IsHitTestVisible="False"/>

Then, of course, you will want to be careful of the back button

CoreApplicationViewTitleBar titleBar = CoreApplication.GetCurrentView().TitleBar;
titleBar.LayoutMetricsChanged += TitleBar_LayoutMetricsChanged;

private void TitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
{
    AppTitle.Margin = new Thickness(CoreApplication.GetCurrentView().TitleBar.SystemOverlayLeftInset + 12, 8, 0, 0);
}

Best of luck!



来源:https://stackoverflow.com/questions/47078264/extend-buttons-to-title-bar-in-uwp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!