windows 我如何从winui自定义标题栏删除灰色覆盖?

kulphzqa  于 2023-03-24  发布在  Windows
关注(0)|答案(1)|浏览(165)

我在一个winui应用程序中创建了一个自定义标题栏,代码如下:

<Border
            x:Name="AppTitleBar"
            Grid.Column="1"
            Background="Transparent"
            Height="{Binding ElementName=NavView, Path=CompactPaneLength}"
            Margin="48,0,0,0"
            VerticalAlignment="Top"
            Canvas.ZIndex="1"
            IsHitTestVisible="True">
            <StackPanel Orientation="Horizontal">
                <!--<Image Width="18" Source="ms-appx:///Assets/Tiles/TitlebarLogo.png" />-->
                <TextBlock
                    x:Name="AppTitle"
                    Margin="16,0,0,0"
                    VerticalAlignment="Center"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="Dynamo Desktop" />
            </StackPanel>
        </Border>

在C#中:

Window window = App.MainWindow;
            window.ExtendsContentIntoTitleBar = true;  // enable custom titlebar
            window.SetTitleBar(AppTitleBar);

我一直得到一个灰色的覆盖,就像在这个图像:

我怎么能纠正这个?

f87krz0w

f87krz0w1#

尝试将这些资源添加到您的App.xaml文件以覆盖默认的WindowCaptionBackgroundWindowCaptionBackgroundDisabled资源:

<Application
    x:Class="WinUI3App.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            ...
            <SolidColorBrush x:Key="WindowCaptionBackground" Color="Transparent"/>
            <SolidColorBrush x:Key="WindowCaptionBackgroundDisabled" Color="Transparent"/>
        </ResourceDictionary>
    </Application.Resources>
</Application>

相关问题