在 UWP 中将按钮扩展到标题栏 [英] Extend buttons to title bar in UWP
问题描述
有没有一种简单的方法可以将窗口控件扩展到标题栏并使其可点击?
Is there a simple way to extend window controls into the title bar and make them clickable?
我阅读了相关帖子(How自定义 UWP 页面的应用程序标题栏),我了解如何在视觉上扩展到标题栏区域.但是,我的按钮在该区域不可点击(好像它们上面有一层,防止它们被点击).
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).
推荐答案
当然,你从
//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);
}
祝你好运!
这篇关于在 UWP 中将按钮扩展到标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!