Search code examples
c#wpfxamlavalondock

Change style of existing theme (AvalonDock)


I want to change the Metro theme color of AvalonDock. I also asked a related question on Codeplex but I didn't got an answer so far.

I identified the following XAML (source file) as the piece that, I guess, is responsible for the color I want to change:

<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).

Now I changed the color like that in my 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?


Solution

  • 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:

    • 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

    After that it worked.