为什么 System.Windows.Controls.Button 总是有 10px 的填充? [英] Why does System.Windows.Controls.Button always have a padding of 10px?
本文介绍了为什么 System.Windows.Controls.Button 总是有 10px 的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
见截图.带有青色边框的框是按钮,而蓝色填充是矩形.我一生都无法弄清楚如何摆脱按钮中的填充.有没有办法将矩形定位到左上角,使其接触青色边框?
See screenshot. The bounding cyan-bordered box is the button, while the blue fill is the rectangle. I cannot for the life of me figure out how to get rid of the padding in the button. Is there a way to position the rectangle to the top left so it touches the cyan border?
谢谢.
推荐答案
您是否尝试将 Rectangle
的边距设置为 0
?
Did you try setting the Rectangle
's margin to 0
?
<Button x:Name="Button" BorderThickness="0" Margin="0" Padding="0" Width="96" Height="96">
<Rectangle Fill="Blue" Margin="0" Width="96" Height="96" />
</Button>
EDIT:填充必须来自按钮控件模板.尝试使用自定义模板:
EDIT: The padding must come from the button control template. Try using a custom template:
<Style x:Key="MyButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle Fill="Blue" Margin="0" Width="96" Height="96" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Button x:Name="Button" BorderThickness="0" Margin="0" Padding="0"
Width="96" Height="96" Style="{StaticResource MyButton}" />
这篇关于为什么 System.Windows.Controls.Button 总是有 10px 的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文