如何动态更改Expander Header背景?

时间:2012-03-06 13:51:37

标签: wpf expander

我的窗口里有一些扩展器...... 我希望当我的Expander扩展时它的标题背景改变了......  我该怎么做?

1 个答案:

答案 0 :(得分:2)

<Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
    <Style.Triggers>
        <Trigger Property="IsExpanded" Value="True">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border Background="Green">
                            <ContentControl Content="{Binding}"/>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
        <Trigger Property="IsExpanded" Value="False">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border Background="Red">
                            <ContentControl Content="{Binding}"/>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>