I'm working with XAML in Windows 8 Metro.
I have a grid with multiple rows. The first row contains a button, and the second an image. The image is a full 600 units wide, and the button has an image content. The problem is that no matter how I style the button, its left edge doesn't match the left edge of the image. While poking around with the settings, it looks like the button includes an extra margin outside of the border, even though I've set the margin (and padding, and border thickness) of the button to 0.
Where does this border come from? How do I get rid of it? I tried creating a custom style with a Template value (below) but it ignores my other style settings. I couldn't find much useful documentation on how to build the template -- or even if that is the problem.
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<ContentPresenter Content="{TemplateBinding Content}" Margin="0" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
When trying to stylize the button with a custom background, it gets really annoying to have this fixed background. You can remove the padding around the button by using setting the minWidth and minHeight to 0.
There are several methods that we can use to put spacing between two buttons. But the easiest way to achieve this is by using the margin property. You can either apply margin-right on the first button or margin-left on the second button. Both ways you can achieve the same task.
It is really annoying. The solution that seems to work for me is:
<Button Background="Crimson"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderThickness="0"
Margin="-3">Click me!</Button>
The secret is in the negative value of margin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With