【发布时间】:2020-04-16 20:46:12
【问题描述】:
以前的解决方案似乎都不起作用。我有一些经过大量修改的按钮,如下所示:
而且,如您所见,按钮中的文本太高了。它需要降低。更改边距不起作用。找不到任何可以调整类型出现在按钮中的位置。这是 XAML:
<Button Grid.Row="0" x:Name="LaunchArmyEditor" Content="Run the General Staff Army Editor" Height="86" Width="600" Click="LaunchArmyEditor_Click" FontFamily="Amaltea WF" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0,0,0,0" BorderBrush="{x:Null}" FontWeight="Bold" Cursor="Hand" Margin="0,-1,0,0" >
<Button.Background>
<ImageBrush ImageSource="TransVictorianButton.png" Stretch="None"/>
</Button.Background>
</Button>
<Button Grid.Row="1" x:Name="LaunchMapEditor" Content="Run the General Staff Map Editor" Height="86" Width="600" Click="LaunchMapEditor_Click" FontFamily="Amaltea WF" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0,0,0,0" BorderBrush="{x:Null}" FontWeight="Bold" Cursor="Hand" >
<Button.Background>
<ImageBrush ImageSource="TransVictorianButton.png" Stretch="None"/>
</Button.Background>
</Button>
有什么建议吗?
【问题讨论】:
-
您是否尝试设置
Padding属性? -
好的,谢谢。它在 Layout 下,而不是 Text,所以我没有想到。
-
您应该使用可重复使用的样式和模板,而不是一遍又一遍地使用几乎相同的标记。问题可能是字体。那些 walden 字体不能正确测量。至于如何解决这个问题。当您将按钮(或标签)的内容设置为字符串时,控件中有代码在控件中插入文本块并将其文本绑定到内容属性。因此,您有一个文本块是按钮的内容,您可以使用按钮的资源对其应用样式。
标签: wpf xaml button text fonts