更改 CommandBar (AppBar) 颜色

Change CommandBar (AppBar) colors

我想更改 CommandBar 的 BackgroundForeground 的背景颜色。但是,简单地设置 Background="whatever" Foreground="whatever" 不会改变溢出部分。

我使用模板和样式等尝试了几个小时,但我真的不知道我在做什么,所以它没有用。我读过 https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/styling-controls and https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/control-templates(以及其他内容,例如本网站上的许多问题),它们实际上只是告诉您存在更改样式这样的事情,并且它们向您展示了如何将元素设置为特定样式。但它们不会向您显示哪些元素具有哪些可用变量...此外,当右键单击 CommandBar - 编辑样式 - 编辑副本时 - 我得到的是一个空的,它会立即使 CommandBar 不可见。这对我来说没有意义。

那么 - 如何更改 CommandBar 的 style/template?

此博客 post 详细介绍了如何解决溢出问题:

https://metronuggets.com/2015/08/04/universal-windows-apps-appbars-and-custom-colours/

它涉及为溢出情况指定样式。

主要魔法在这里:

<Page.BottomAppBar>
    <CommandBar Background="Blue"
                Foreground="White">
        <CommandBar.CommandBarOverflowPresenterStyle>
            <Style TargetType="CommandBarOverflowPresenter">
                <Setter Property="Background"
                        Value="Blue" />
            </Style>
        </CommandBar.CommandBarOverflowPresenterStyle>
        <CommandBar.PrimaryCommands>
            <AppBarButton Label="settings"
                          Icon="Setting"
                          Foreground="White"/>
        </CommandBar.PrimaryCommands>
        <CommandBar.SecondaryCommands>
            <AppBarButton Label="about"
                          Foreground="White"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>