简体   繁体   中英

WPF Override Style Value

I'm using MaterialDesignInXaml for WPF which provides 3rd party controls and styles. I need to edit one of these styles by changing one property.

I am using an Expander control which has a template creating a bunch of child controls. I've discovered the child 'Border' control (4 layers deep) has the property (padding) which I need to set to zero.

See this output from Snoop showing the property I need to change: Link to image

My question is how can I do this? I've tried extending the style used by the control as follows, but it isn't changing anything so I assume I'm doing something wrong?

<Style TargetType="{x:Type Expander}" 
         x:Key="MaterialDesignExpanderHeadless" 
         BasedOn="{StaticResource MaterialDesignExpander}">
    <Style.Resources>
        <Style TargetType="{x:Type Border}">
            <Setter Property="Padding" Value="0"></Setter>
        </Style>
    </Style.Resources>
</Style>

I am able to use the style like this. And I know this is working for sure:

<Expander Header="Header Content" Style="{StaticResource MaterialDesignExpanderHeadless}">
    Some Content
</Expander>

You're right, this method should work. Something else is setting the border's padding.

Snoop is telling you the padding is defined by the parent template, which could be the HeaderSite (ToggleButton). You could try to extend the ToggleButton style (BasedOn) or redefine it locally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM