gpt4 book ai didi

wpf - 如何设置分组框内子控件的字体?

转载 作者:行者123 更新时间:2023-12-01 22:33:31 24 4
gpt4 key购买 nike

当我为组框设置不同的字体时,子控件也设置为组框的字体。

我必须为每个子控件设置不同的字体属性。

就像我必须将子控件的 Font 属性设置为

<GroupBox Font Size = "14"> <Label FontWeight"Normal" ,Font Size ="8"/> <TextBox FontWeight"Normal" ,Font Size ="8"/>  </GroupBox>

这是设置组框中每个子项的字体属性的最佳方法吗?

请大家推荐!!

最佳答案

如果您希望 GroupBox 中的标签尺寸较小,并且组框中的其他所有内容都与 GroupBox 标题文本大小相匹配,请使用以下样式:

<GroupBox FontSize="14" Header="Header Text">
<GroupBox.Resources>
<Style TargetType="Label">
<Setter Property="FontSize" Value="8" />
<Setter Property="FontWeight" Value="Normal" />
</Style>
</GroupBox.Resources>

<StackPanel>
<Label Text="Label Text" />
<Label Text="Another Label" />
<TextBlock Text="This will match the group header" />
</StackPanel>
</GroupBox>

如果您希望 GroupBox header 与 GroupBox 中的所有文本不同,请使用 TextBlock 作为 header 而不是字符串:

<GroupBox>
<GroupBox.Header>
<TextBlock Text="Header Text" FontSize="14" />
</GroupBox.Header>

<StackPanel>
<Label Text="Label Text" />
<Label Text="Another Label" />
<TextBlock Text="This will be the default font" />
</StackPanel>

</GroupBox>

这两种技术可以结合起来,为 GroupBox 标题提供一种尺寸,为标签提供另一种尺寸,为 GroupBox 中的所有其他文本提供第三种(默认)尺寸。

关于wpf - 如何设置分组框内子控件的字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2422249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com