背景
前一篇博文留下了一个遗憾: 用户切换应用主题时应用主体内容会发生响应, 但标题栏无法随之改变. 本文探讨标题栏的修正.
标题栏按钮颜色设置
不去弄选择分支了. 直接打一个字典就行. 此处我的设置如下:
Item | Note | Light Color / RGB | Dark Color / RGB |
---|---|---|---|
ButtonBackgroundColor | 普通状态下按钮背景色 | Transparent | Transparent |
ButtonForegroundColor | 普通状态下按钮前景色 | Black | White |
ButtonInactiveBackgroundColor | 窗口未激活状态下按钮背景色 | Transparent | Transparent |
ButtonInactiveForegroundColor | 窗口未激活状态下按钮前景色 | 144, 144, 144 | 96, 96, 96 |
ButtonHoverBackgroundColor | 光标位于按钮上时按钮背景色 | 233, 233, 233 | 45, 45, 45 |
ButtonHoverForegroundColor | 光标位于按钮上时按钮前景色 | Black | White |
ButtonPressedBackgroundColor | 光标按下时按钮背景色 | 237, 237, 237 | 41, 41, 41 |
ButtonPressedForegroundColor | 光标按下时按钮前景色 | 95, 95, 95 | 167, 167, 167 |
此处注意三个问题:
- 应用使用了
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
将应用内容扩展至标题栏 - 当设置主题为 Adaptive (Default) 时应将颜色值设置为
null
, 此时颜色值会回落为系统默认状态. 此时我仍将ButtonBackgroundColor
和ButtonInactiveBackgroundColor
设置为透明, 避免标题栏的割裂感. - 表中除上面提到的两项, 其他色值均与 Windows 系统相同.
实现步骤
- 先封装一个公共方法, 用于根据主题设置标题栏;
- 在应用启动时调用;
- 在切换主题时调用.
OVER.
附
在设计随系统切换主题时, 其实一早就注意到 ActualThemeChanged
事件, 准备先试一下将颜色设置为 null
看能不能行得通. 结果还比较满意, 就不考虑这个事件了嗷.
转载请注明来源。
文章地址 https://blog.csdn.net/brandonw3612/article/details/119846875