WinUI 3 标题栏自定义

问题描述 投票:0回答:1

我是 WinUI 新手,正在努力做一些基本的事情。如有任何帮助,我们将不胜感激。

1.) 有没有办法在WinUI 3中显示或隐藏标题栏中的默认图标。我尝试在this.SetIcon(null)中设置null。但标题栏中仍然显示默认图标。

2.) 当使用ExtendsContentsIntoTitleBar = true时,有没有办法隐藏最小化和最大化按钮。即使我使用WinUIEx扩展方法, 喜欢 this.SetIsMinimized(false);或者 this.SetIsMaximized(false); 这些没有按预期工作,最小化/最大化按钮仍然显示。

desktop-application winui-3 winui
1个回答
0
投票

有一种方法可以隐藏最大化/最小化按钮和图标。

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;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.