Search code examples
wpfstylesexpander

Styling the content section of an Expander control


How do you apply a style to the content section of an Expander control?


Solution

  • Figured it out:

        <Style x:Key="ListItem" TargetType="{x:Type Expander}">
            <Setter Property="BorderBrush" Value="{StaticResource DefaultBorder}"/>
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
            <Setter Property="Padding" Value="0,2"/>
    
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border BorderBrush="{StaticResource DefaultBorder}" BorderThickness="0,1,0,0">
                            <Grid>
                                 <Border Background="Transparent" Padding="0,10,0,10" >
                                    <ContentControl Margin="24,0,0,0" Content="{TemplateBinding Content}"/>
                                </Border>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

    I needed the ContentControl. :)