是否有一种简单的方法可以制作完全正方形Button
?通常情况下,Button
有点圆,所以我该如何实现呢?
答案 0 :(得分:5)
只需创建自定义按钮样式......就像这样
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="FontFamily"
Value="Arial Narrow" />
<Setter Property="FontSize"
Value="13" />
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="20"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="BorderBrush" Value="#FF1733D2"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border" Background="#FF1733D2">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果您有Blend,请单击按钮...编辑样式 - &gt;编辑当前...并摆脱我认为的角落半径
答案 1 :(得分:4)
如果您的意思是宽度=身高,请参阅WPF dynamic layout: how to enforce square proportions (width equals height)?
如果您的意思是方角,请将边框的 CornerRadius 设置为零:
<ControlTemplate x:Key="SquareButton" TargetType="{x:Type Button}">
<Border CornerRadius="0"/>
</ControlTemplate>
然后该按钮使用该模板:
<Button Template="{StaticResource SquareButton}"/>