为什么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?
感谢。
推荐答案
你有没有尝试长方形
的页边距设置为 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: 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屋!
查看全文