开发者

Customizing WPF Expander; Make only icon clickable not whole header

I want an Expander that only expands/collapse it's content when the user clicks on the header icon. (Instead of the whole header being clickable.)

Do I have to redefine the control Template to do this? How would it look l开发者_开发问答ike?

Where can I find the standard templates/styles for controls?

Thanks for your time.


There is actually a much simpler XAML solution than modifying templates. Simply DON'T use the Expander's header property in this case. Instead, cover the expander with your own styled TextBlock.

<Application.Resources>
    <Style x:Key="ExpanderHeader" TargetType="{x:Type TextBlock}">
        <Setter Property="Height" Value="22" />
        <Setter Property="Margin" Value="21,0,0,0" />
        <Setter Property="Padding" Value="9,3,0,0" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Top" />
    </Style>
</Application.Resources>

<Grid>
    <Expander>
        <TextBlock Text="I am some content. I have disowned my default header." Margin="10,5" />
    </Expander>
    <TextBlock Text="I'm filling in for the default header. You'll like me better anyway."
               Style="{StaticResource ResourceKey=ExpanderHeader}"/>
</Grid>


I posted a solution to my question here (same link as in the comment from Ben).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜