This commit is contained in:
1 parent
72d9b295a0
commit
5d81c475c8
335 files changed
+7359
No files matched your search
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: handycontrol-wpf-theming
|
||||
description: "配置 HandyControl WPF 的皮肤、资源字典、动态颜色和主题切换;排查资源键与控件样式,不用于 Avalonia。"
|
||||
---
|
||||
|
||||
# HandyControl WPF 主题
|
||||
|
||||
程序集/NuGet 为 `HandyControl`,XAML 命名空间为
|
||||
`xmlns:hc="https://handyorg.github.io/handycontrol"`,C# 控件命名空间为 `HandyControl.Controls`。
|
||||
在 `App.xaml` 合并 `pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml`,
|
||||
然后合并 `pack://application:,,,/HandyControl;component/Themes/Theme.xaml`。
|
||||
已有主题配置时先检查,避免重复合并。版本和目标框架以使用方项目为准。
|
||||
|
||||
按任务阅读 [配置及示例](references/usage.md)。先确认控件实际 CLR 类型和样式 TargetType,再修改资源。
|
||||
@@ -0,0 +1,4 @@
|
||||
interface:
|
||||
display_name: "HandyControl WPF 主题"
|
||||
short_description: "Implement HandyControl WPF controls from verified source guidance"
|
||||
default_prompt: "Use $handycontrol-wpf-theming to implement the requested HandyControl WPF UI."
|
||||
@@ -0,0 +1,41 @@
|
||||
# 皮肤、主题与资源
|
||||
|
||||
## 静态字典方案
|
||||
|
||||
`SkinDefault.xaml`、`SkinDark.xaml`、`SkinViolet.xaml` 是皮肤字典;`Theme.xaml` 提供控件主题。先合并一个皮肤,再合并主题,应用自己的覆盖资源置于其后。通过 `DynamicResource` 引用需要随皮肤变化的颜色和画刷,例如 `PrimaryBrush`、`RegionBrush`;显式样式键通常用 `StaticResource`。
|
||||
|
||||
```xml
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDark.xaml"/>
|
||||
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
```
|
||||
|
||||
这是现有 ResourceDictionary 内的片段,不应额外嵌套 Application.Resources。运行时更换静态皮肤时替换由应用持有的那一个皮肤字典,保留其他字典和顺序,不清空全部 MergedDictionaries。
|
||||
|
||||
## Theme 对象方案
|
||||
|
||||
当前源码还提供 `HandyControl.Themes.Theme : ResourceDictionary`,其 `Skin` 为 `HandyControl.Data.SkinType`;可以用 Theme 对象管理皮肤。采用此方案时先读取 `Themes/Theme.cs` 的构造和更新逻辑,避免同时再加载一套静态主题字典。
|
||||
|
||||
```xml
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<hc:Theme Skin="Dark"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
```
|
||||
|
||||
`hc` 对应 `https://handyorg.github.io/handycontrol`。修改 Theme 实例的 Skin 需要保留对该实例的引用;自动跟随系统、强调色等能力以实际版本的 Theme 源码属性为准。
|
||||
|
||||
## 调整外观
|
||||
|
||||
先找到控件对应的 `Themes/Styles/<控件>.xaml`,核对 x:Key、TargetType、BasedOn 和 TemplateBinding。能通过公开属性或附加属性完成的改动优先使用这些接口;确需重写模板时保留必需的 PART_* 名称。
|
||||
|
||||
本仓库 `Themes/Theme.xaml` 由 `XamlCombine.exe` 和 `Theme_GE45.txt` / `Theme_40.txt` 合并。修改相应样式源文件及必要的清单,再按项目构建流程生成;不要把合并文件当作唯一维护入口。使用方项目通常只需要覆盖自己的资源。
|
||||
|
||||
先检查工作区已有修改,尤其颜色和主题文件,避免覆盖用户的定制。验证浅色、深色切换时检查文本对比度、禁用态、弹出层及局部资源覆盖;无法运行 UI 时说明限制。
|
||||
|
||||
## 源码依据
|
||||
|
||||
- [Theme 实现](https://github.com/HandyOrg/HandyControl/blob/master/src/Shared/HandyControl_Shared/Themes/Theme.cs)
|
||||
- [皮肤枚举](https://github.com/HandyOrg/HandyControl/blob/master/src/Shared/HandyControl_Shared/Data/Enum/SkinType.cs)
|
||||
- [样式源目录](https://github.com/HandyOrg/HandyControl/tree/master/src/Shared/HandyControl_Shared/Themes/Styles)
|
||||
- [主题合并清单](https://github.com/HandyOrg/HandyControl/blob/master/src/Shared/HandyControl_Shared/Themes/Theme_GE45.txt)
|
||||
Reference in new issue
Block a user