I think Vasileโs answer is on the right track, but it looks like it is much bigger than the original poster. The entire original question asked was to change the background of the title. Although the presented change does this, it also does other things.
One of these things is to replace the default implementation, I believe that ContentPresenter with TextBlock. So what happens when we add a second expander to this stack pane? Maybe something like:
<Expander> <Expander.Header> <StackPanel> <Border height="5" width="5" Foreground="Blue"/> <TextBlock>Ha!</TextBlock> </StackPanel> </Expander.Header> </Expander>
I donโt know, but itโs not good. Instead, I think we want to keep it simple.
<DataTemplate x:Key="expanderHeader"> <ContentPresenter Content={Binding} TextBlock.Background={StaticResource myBrush}/> </DataTemplate> <Style TargetType="Expander"> <Setter Property="HeaderTemplate" Value="{StaticResource expanderHeader}"/> </Style>
Thus, when someone puts something that is not just text in our stylized expander, we will not break. If you want to make sure that you have completely linked everything that they do with this background, that would probably be desirable:
<DataTemplate x:Key="expanderHeader"> <Border Background={StaticResource myBrush}> <ContentPresenter Content={Binding}/> </Border> </DataTemplate>
PatrickV May 16 '14 at 14:09 2014-05-16 14:09
source share