0

I'm currently trying to style the ToggleButton in the Expander control but I can't figure out how to change it's Background color and the Foreground color.

I've currently managed to change the Text in the border but I can seem to find how to target the ToggleButton, is it under some other name?

This is what I've got so far.

<Style TargetType="Border" x:Key="RacePitBorderStyle" >
        <Setter Property="Background" Value="{StaticResource BackBrush}"/>
    </Style>


    <DataTemplate x:Key="titleText">
        <Border Style="{StaticResource RacePitBorderStyle}" Height="24">
            <TextBlock Text="{Binding}"
                           Margin="75,0,0,0"
                           VerticalAlignment="Center"
                           Foreground="White"
                           FontSize="11" 
                           FontWeight="Medium"
                           Width="{Binding
                        RelativeSource={RelativeSource
                        Mode=FindAncestor,
                        AncestorType={x:Type Expander}},
                        Path=ActualWidth}"/>
        </Border>
    </DataTemplate>

    <Style TargetType="{x:Type Expander}">
        <Setter Property="HeaderTemplate" Value="{StaticResource titleText}"/>
    </Style>
Mark Denom
  • 987
  • 1
  • 8
  • 24
  • You should create your own `ControlTemplate` with `ToggelButton` in target type, have a look at existing threads [here](https://stackoverflow.com/questions/10143989/default-controltemplate-for-expander) and [here](https://stackoverflow.com/questions/7714154/wpf-expander-button-style-with-and) MSDN also has a good [article](https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/expander-styles-and-templates) – Pavel Anikhouski Jul 21 '19 at 11:21
  • I'm not quite sure how I would target the Expanders ToggleButton though, if I were to make a controltemplate for the Expander, how do I target the ToggleButton? – Mark Denom Jul 21 '19 at 11:28

0 Answers0