In a large WPF-project setting padding on buttons does not have any effect what so ever. No styles, templates, etc are set on the button, but still it won’t use my padding.
<StackPanel>
<Button Padding="20, 20">Hello</Button>
</StackPanel>
I tried this in a brand new project and it works like a charm. Obviously there is some global style, template somewhere in the project causing this. Either somewhere in the xaml file, or in some resource file. As this project is rather hefty I going through everything is not feasable.
How to I debug this? Can I see what is overriding the padding?
I tried snooping around with Snoop 2.7.0, but it didn’t really tell me much. Any hints on how to proceed with this type of error?
EDIT
I loked at the ValueSource for some properties:
- Padding=Local
- ContentTemplate=Default
- Template=Style
This particular problem was caused by a style defined in a resource included in the
App.xaml.The important lesson here is that styles without the
x:Keyattribute will affect all elements of the target type as described here.Performing a solution wide wild card search on
<Style*TargetType="*Buttonyielded a list of potential styles that would affect my button. I found one without thex:Keyattribute, commented it out just to try and voila! The padding works.