有没有一种简单的方法可以将窗口控件扩展到标题栏并使其可点击?
我阅读了相关帖子(如何为 UWP 页面自定义应用程序标题栏),并且了解如何直观地扩展到标题栏区域。但是,我的按钮在该区域不可点击(好像它们上面有一层,防止它们被点击)。
当然可以,你从
//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;
Run Code Online (Sandbox Code Playgroud)
从那里开始,只需将按钮放置在正确的空间即可。
这也会很有帮助,因为您将消除您的应用程序标题:
<!-- Page attribute -->
xmlns:appmodel="using:Windows.ApplicationModel"
<TextBlock x:Name="AppTitle" Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind appmodel:Package.Current.DisplayName}" IsHitTestVisible="False"/>
Run Code Online (Sandbox Code Playgroud)
然后,当然,您需要小心后退按钮
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);
}
Run Code Online (Sandbox Code Playgroud)
祝你好运!