c# - 更改 CommandBar (AppBar) 颜色

标签 c# xaml win-universal-app uwp uwp-xaml

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

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

那么 - 如何更改 CommandBar 的样式/模板?

最佳答案

这篇博文详细介绍了如何解决溢出问题:

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>

关于c# - 更改 CommandBar (AppBar) 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304315/

相关文章:

c# - 无法加载 {myassembly} 导入的过程

c# - Hook 到 Quartz.net 中的关闭方法

c# - xaml DataGrid 绑定(bind)到字典中的字典中的字典

c# - 等待 DeviceInformation.FindAllAsync(selector) 并引用 System.Runtime.WindowsRuntime 时出错

windows-8 - 通用 Windows 平台是否会取代 Windows 8 和 Windows Phone 应用程序的 WinRT?

c# - 如何在上传前选择图片并裁剪?

c# - 返回 C# 后保留 C++ 中的类状态

c# - JAVA垃圾收集副作用——阻塞?

c# - 获取 Button 内的 TextBlock

wpf - 单击按钮时将填充设置为 LinearGradientBrush