wpf 更改现有主题的样式(AvalonDock)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25722664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change style of existing theme (AvalonDock)
提问by fedab
I want to change the Metro theme color of AvalonDock. I also asked a related question on Codeplexbut I didn't got an answer so far.
我想更改 AvalonDock 的 Metro 主题颜色。我也在Codeplex 上问了一个相关的问题,但到目前为止我还没有得到答案。
I identified the following XAML (source file) as the piece that, I guess, is responsible for the color I want to change:
我将以下 XAML(源文件)确定为我想更改颜色的部分:
<Style TargetType="avalonDockControls:AnchorablePaneTitle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
...
<ControlTemplate.Triggers>
...
<DataTrigger Binding="{Binding Model.IsActive, RelativeSource={RelativeSource Mode=Self}}" Value="True">
<!-- following XAML line -->
<Setter Property="BorderBrush" Value="{DynamicResource AvalonDock_ThemeMetro_BaseColor3}" />
<Setter Property="BorderThickness" Value="0,3,0,0"/>
</DataTrigger>
...
</ControlTemplate.Triggers>
...
You can see: the brush gets the BaseColor3 (a bluish color by default).
您可以看到:画笔获得了 BaseColor3(默认为蓝色)。
Now I changed the color like that in my XAML:
现在我更改了 XAML 中的颜色:
<Window.Resources>
...
<SolidColorBrush x:Key="AvalonDock_ThemeMetroBaseColor3" Color="Red" />
</Window.Resources>
Nothing changes. The color stay bluish. Now I am confused. So it must be the wrong property to change or something prevents the color to change or/and internal it uses the old value or something...
没有什么改变。颜色保持蓝色。现在我很困惑。因此,更改必须是错误的属性,或者某些东西会阻止颜色更改或/和内部使用旧值或其他东西......
Why is it not working? How can I discover such problems and fix it?
为什么它不起作用?我怎样才能发现这些问题并解决它?
回答by fedab
I guess the problem was this:
我想问题是这样的:
<avalon:DockingManager>
<avalon:DockingManager.Theme>
<avalon:MetroTheme />
</avalon:DockingManager.Theme>
...
</avalon:DockingManager>
I removed the theme setting and created an own Resource dictionary (copied the style from the AvalonDock source). I had to fix some errors:
我删除了主题设置并创建了一个自己的资源字典(从 AvalonDock 源中复制了样式)。我不得不修正一些错误:
- BaseColorXX not found -> copy from VS2010 theme of an older AvalonDock version
- TargetType 'HwndHostInstance' not match with type of element "LayoutAutoHideWindowControl -> comment out the Style with x:Key="{x:Type avalonDockControls:LayoutAutoHideWindowControl}")
- Remove
BasedOn="{Static Resource {x:Type MenuItem}}"(caused an error) - Change the image paths to my own project path with the copied images
- 未找到 BaseColorXX -> 从旧 AvalonDock 版本的 VS2010 主题复制
- TargetType 'HwndHostInstance' 与元素类型“LayoutAutoHideWindowControl -> 用 x:Key="{x:Type avalonDockControls:LayoutAutoHideWindowControl}" 注释掉样式不匹配
- 删除
BasedOn="{Static Resource {x:Type MenuItem}}"(导致错误) - 使用复制的图像将图像路径更改为我自己的项目路径
After that it worked.
在那之后它起作用了。

