debugging 在WinUI 3中显示白色的自定义标题栏

guykilcj  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(221)

我的浏览器又出现了另一个问题。我做了一个自定义的标题栏,标签进入标题栏,以创造一个更身临其境的体验。但所有的“身临其境的体验”正在被这个似乎无法修复的错误破坏。我试图做的是改变CustomDragRegion元素的背景。

看看标题栏,真恶心,谁来帮帮我
下面是代码:

<Window
x:Class="Microsoft_Edge_WebView2_Runtime_Application.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft_Edge_WebView2_Runtime_Application"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">
<Grid BorderBrush="Transparent" x:Name="Browser" Margin="0,0,0,0" Background="{ThemeResource SystemControlBackgroundAccentRevealBorderBrush}">
    <TabView Margin="0, 0, 0, 0" x:Name="Tabv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AddTabButtonClick="TabView_AddTabButtonClick" TabCloseRequested="TabView_TabCloseRequested">
        <TabViewItem FontFamily="Gellix" x:Name="HomeTab" Header="Home" IsClosable="False">
            <TabViewItem.IconSource>
                <SymbolIconSource Symbol="Document" />
            </TabViewItem.IconSource>

            <Grid x:Name="TabContent" Margin="0,0,0,0" Background="#282828">
                <WebView2 x:Name="WebView" Source="https://google.com" Margin="0,52,0,0"/>
                <Grid Margin="0,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Width="666">
                    <TextBox KeyDown="AddressBar_KeyDown" FontFamily="Gellix" x:Name="AddressBar" HorizontalAlignment="Center" TextWrapping="NoWrap" Text="" VerticalAlignment="Center" Width="576" PlaceholderText="Search or type a URL here..." TextAlignment="Center" />
                    <Button Height="32" Width="40" x:Name="Home" Click="Button_Click_1">
                        <FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xE80F;" Margin="-2,-1,-2,-1"/>
                    </Button>
                    <Button Height="32" Width="40" x:Name="Go" Margin="626,0,0,0" Click="Button_Click">
                        <FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xE751;" Margin="-2,-1,-2,-1"/>
                    </Button>
                </Grid>
                <Button x:Name="Refresh" Margin="0,10,10,0" VerticalAlignment="Top" Height="32" Width="40" FontFamily="Segoe UI Symbol" Click="Button_Click" HorizontalAlignment="Right">
                    <FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xe72c;" Margin="-2,-1,-2,-1"/>
                </Button>
                <Button x:Name="Backward" Margin="10,10,0,0" VerticalAlignment="Top" Height="32" Width="40" FontFamily="Segoe UI Symbol" Click="Backward_Click">
                    <FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xf0d3;" Margin="-2,-1,-2,-1"/>
                </Button>
                <Button x:Name="Forward" Margin="53,10,0,0" VerticalAlignment="Top" Height="32" Width="40" FontFamily="Segoe UI Symbol" Click="Forward_Click">
                    <FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xF0D2;" Margin="-2,-1,-2,-1"/>
                </Button>
            </Grid>
        </TabViewItem>
        <TabView.TabStripFooter>
            <Grid Margin="0,0,0,0"  x:Name="CustomDragRegion" Background="Transparent"/>
        </TabView.TabStripFooter>
    </TabView>

</Grid>

如果你真的需要c#代码,那么就注解一下。因为我只有两行c#代码与标题栏相关。

piztneat

piztneat1#

在我的示例中,我可以通过将WindowCaptionsBackgroundWindowCaptionsBackgroundDisabled属性设置为Transparent,将title栏设置为xaml中定义的颜色,如下所示:
App.xaml

<Application
    ...
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                <!-- Other merged dictionaries here -->
            </ResourceDictionary.MergedDictionaries>
            <!-- Other app resources here -->
            <SolidColorBrush x:Key="WindowCaptionBackground">Transparent</SolidColorBrush>
            <SolidColorBrush x:Key="WindowCaptionBackgroundDisabled">Transparent</SolidColorBrush>
        </ResourceDictionary>
    </Application.Resources>
    
</Application>

有关自定标题栏的更多信息:https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=winui3

相关问题