单击标题时防止WPF扩展器扩展

M. *_*ley 12 wpf xaml expander

如何Expander在单击标题时阻止WPF 扩展?我希望Expander仅在单击展开按钮本身时展开或折叠.

我想这个答案与取消泡沫事件有关.如果可能的话,我想在XAML中实现解决方案,同时避免重复整个解决方案Expander.

bug*_*d87 16

实际上,比修改模板更简单的XAML解决方案.在这种情况下,不要使用Expander的头属性.而是使用您自己的样式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>
Run Code Online (Sandbox Code Playgroud)


Sim*_*rim 3

标题是创建事件的按钮,因此您需要更改 Expander 的模板,仅将 Expander 图标作为按钮。

这是一篇如何更换扩展器的帖子。