Search code examples
c#wpf.net-4.5ribbon

Change Backgroundcolor of TabControl


I'm using the .NET 4.5 WPF Ribbon and want to change the background color of one particular RibbonTab, in all situations (independent of whether it is selected, hovered over, or not - don't ask why). Usually I'd look at the code of the template in Blend but trying to copy the style fails with the error "could not copy template".

So far I have the following:

<RibbonTab.HeaderStyle>
    <Style TargetType="RibbonTabHeader" BasedOn="{StaticResource {x:Type RibbonTabHeader}}">
        <Setter Property="Background" Value="Red" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="Yellow" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</RibbonTab.HeaderStyle>

The problem is that I cannot seem to find out a way on how to change the color when the tab control is selected.


Solution

  • I can't comment, because I don't have enough reputation yet.

    The RibbonTabHeader has the following properties:

    • CheckedBackground - Gets or sets the brush that is used to draw the background of the control when it is in the Checked state.
    • FocusedBackground - Gets or sets the brush that is used to draw the background of the control when it has focus.
    • MouseOverBackground - Gets or sets the brush that is used to draw the background of the control when the mouse is over it.
    • Background - Gets or sets a brush that describes the background of a control. (Inherited from Control.)

    Have you tried setting the MouseOverBackground to Yellow, the CheckedBackground to the color you would like to use when it's selected and the Background for the "not selected, not hovering" state.