简体   繁体   English

WinUI 3 标题栏自定义

[英]WinUI 3 Title Bar Customization

I am new to WinUI and struggling to do some basic things in that.我是 WinUI 的新手,正在努力做一些基本的事情。 Any help is appreciated.任何帮助表示赞赏。

1.) Is there any way to show or hide default icon from the title bar in WinUI 3. I tried to set the null in this.SetIcon(null). 1.) 有什么方法可以在 WinUI 3 的标题栏中显示或隐藏默认图标。我试图在 this.SetIcon(null) 中设置 null。 But the default icon is still showing in the Title Bar.但默认图标仍显示在标题栏中。

2.) When using the ExtendsContentsIntoTitleBar = true, Is there any way to hide the Minimize and Maximize buttons. 2.) 当使用 ExtendsContentsIntoTitleBar = true 时,有没有办法隐藏最小化和最大化按钮。 Even if I use the WinUIEx extensions method, like this.SetIsMinimizable(false);即使我使用 WinUIEx 扩展方法,如 this.SetIsMinimizable(false); or this.SetIsMaximizable(false);或 this.SetIsMaximizable(false); These are not working as expected and minimize/maximize button is still showing.这些未按预期工作,最小化/最大化按钮仍在显示。

There is a way to hide the maximize / minimize button.有一种方法可以隐藏最大化/最小化按钮。 And it is also possible to hide the icon.并且还可以隐藏图标。

MainWindow.xaml.cs MainWindow.xaml.cs

// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace WinUI3
{
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            GetAppWindowAndPresenter();
            _presenter.IsMaximizable = false;
            _presenter.IsMinimizable = false;
            _apw.Title = "Title";
            _apw.TitleBar.IconShowOptions = IconShowOptions.HideIconAndSystemMenu;
        }

        public void GetAppWindowAndPresenter()
        {
            var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
            _apw = AppWindow.GetFromWindowId(myWndId);
            _presenter = _apw.Presenter as OverlappedPresenter;
        }
        private AppWindow _apw;
        private OverlappedPresenter _presenter;
    }
}

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

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