Search code examples
c#wpfavalondock

How to modify AvalonDock AnchorablePaneTitle ContentPresenter foreground property when AutoHidden?


I've got an issue with the AvalonDock controls. The header of my pane are white over blue when displayed, black over white when tabbed and should be black over white when AutoHiden and mouse is over the tab (kind of "preview", so not yet docked)... But as a screenshot will describer better the issue than me the issue :

Explorer header is white

And here's the contentpresenter (line 429 of Metro Theme.xaml in the latest source version)

<ContentPresenter 
    x:Name="Header"            
    Margin="5,3"
    TextElement.Foreground="{DynamicResource AvalonDock_ThemeMetro_Foreground}"
    Content="{Binding Model, RelativeSource={RelativeSource TemplatedParent}}" 
    ContentTemplate="{Binding Model.Root.Manager.AnchorableTitleTemplate, RelativeSource={RelativeSource TemplatedParent}}"
    ContentTemplateSelector="{Binding Model.Root.Manager.AnchorableTitleTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"/>

(AvalonDock_ThemeMetro_Foreground is White as the normal foreground for it is over blue, like the title bar)

Should be :

Explorer header is black

Do someone have any idea of who's reponsible for the style change ? I don't have a deep knowledge of how AvalonDocks works internally and my actual research just gave me a basic understanding of the big picture but I can't identify precisely the way to do it.


Solution

  • I've figured out the issue. Apparently, the style applied to the LayoutAnchorableControl is not the one you define but the one from 'generic.xaml' when hosted in a LayoutAutoHideWindowControl. I still don't know why and how, but updating the 'generic.xaml' style fix the issue. I will continue to investigate the why and find a way to make him use the custom style when hosted in a 'LayoutAutoHideWindowControl'.

    EDIT Ok, I figured it out... It was really stupid, when defining the style of the LayoutAutoHideWindow, I didn't pay attention to a property, "AnchorableStyle", allowing you to provide the style to apply to the created LayoutAnchorableControl. So, here's the style for the LayoutAnchorabeControl :

    <!--The "Metro" LayoutAnchorableControl Style-->
    <Style TargetType="{x:Type avalonDockControls:LayoutAnchorableControl}" x:Key="AvalonDock_ThemeMetro_LayoutAnchorableControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type avalonDockControls:LayoutAnchorableControl}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="Header" Background="{DynamicResource AvalonDock_ThemeMetro_HeaderBackground}">
                                <avalonDockControls:AnchorablePaneTitle Model="{Binding Model, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Border>
                            <ContentPresenter Grid.Row="1" FlowDirection="{TemplateBinding FlowDirection}"
                                Content="{Binding LayoutItem.View, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.IsFloating}" Value="True"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Model.Parent.IsDirectlyHostedInFloatingWindow}" Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Visibility" Value="Collapsed" TargetName="Header"/>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!--Apply it as default too-->
    <Style TargetType="{x:Type avalonDockControls:LayoutAnchorableControl}" BasedOn="{StaticResource AvalonDock_ThemeMetro_LayoutAnchorableControl}" />
    

    And here's how to make the LayoutAutoHideWindowControl use it as the style to apply to the LayoutAnchorableControl he creates :

    <Style x:Key="{x:Type avalonDockControls:LayoutAutoHideWindowControl}" TargetType="{x:Type avalonDockControls:LayoutAutoHideWindowControl}">
        <Setter Property="Background" Value="{DynamicResource AvalonDock_ThemeMetro_Background}"/>
        <Setter Property="AnchorableStyle" Value="{StaticResource AvalonDock_ThemeMetro_LayoutAnchorableControl}" />
    </Style>