我只是想知道是否可以将可用的FontStyle
和FontWeight
列表绑定到ComboBox
?
例如,要将字体列表绑定到组合框,您可以使用:
FontComboBox.ItemsSource = Fonts.SystemFontFamilies;
我还可以为:
FontStyleComboBox.ItemsSource = ....
FontWeightComboBox.ItemsSource = .... ?
是否需要对System.Windows.FontWeights
和System.Windows.FontStyles
类进行反思,还是会有更简单的方法?
由于
答案 0 :(得分:11)
对于字体系列组合:
<ComboBox Name="Families" ItemsSource="{x:Static Fonts.SystemFontFamilies}"/>
对于字体样式:
<ComboBox Name="Styles">
<x:Static Member="FontStyles.Normal"/>
<x:Static Member="FontStyles.Italic"/>
<x:Static Member="FontStyles.Oblique"/>
</ComboBox>
对于字体权重:
<ComboBox Name="Weights">
<x:Static Member="FontWeights.Black"/>
<x:Static Member="FontWeights.Bold"/>
<x:Static Member="FontWeights.DemiBold"/>
<x:Static Member="FontWeights.ExtraBlack"/>
<x:Static Member="FontWeights.ExtraBold"/>
<x:Static Member="FontWeights.ExtraLight"/>
<x:Static Member="FontWeights.Heavy"/>
<x:Static Member="FontWeights.Light"/>
<x:Static Member="FontWeights.Medium"/>
<x:Static Member="FontWeights.Normal"/>
<x:Static Member="FontWeights.Regular"/>
<x:Static Member="FontWeights.SemiBold"/>
<x:Static Member="FontWeights.Thin"/>
<x:Static Member="FontWeights.UltraBlack"/>
<x:Static Member="FontWeights.UltraBold"/>
<x:Static Member="FontWeights.UltraLight"/>
</ComboBox>
现在来测试一下:
<TextBlock
Text="This is some text."
FontFamily="{Binding ElementName=Families, Path=SelectedItem}"
FontStyle="{Binding ElementName=Styles, Path=SelectedItem}"
FontWeight="{Binding ElementName=Weights, Path=SelectedItem}"/>
答案 1 :(得分:3)
再一次 -
<ComboBox
Name="FontStretches">
<x:Static
Member="FontStretches.Condensed" />
<x:Static
Member="FontStretches.Expanded" />
<x:Static
Member="FontStretches.ExtraCondensed" />
<x:Static
Member="FontStretches.ExtraExpanded" />
<x:Static
Member="FontStretches.Medium" />
<x:Static
Member="FontStretches.Normal" />
<x:Static
Member="FontStretches.SemiCondensed" />
<x:Static
Member="FontStretches.SemiExpanded" />
<x:Static
Member="FontStretches.UltraCondensed" />
<x:Static
Member="FontStretches.UltraExpanded" />
</ComboBox>
答案 2 :(得分:2)
很棒的帖子!我只想在Font Weights上添加一些东西。 FontWeights类具有上面列出的所有静态属性,它们只是封装了1到999之间的数字。一些具有不同名称的属性封装了相同的值,因此最终会出现重复。另外,上面的例子没有按顺序排列。
参考: - FontWeights Class
这里它们是有序的,重复删除,以及显示每个重量编号的注释:
<!--100-->
<x:Static
Member="FontWeights.Thin" />
<!--200-->
<x:Static
Member="FontWeights.ExtraLight" />
<!--300-->
<x:Static
Member="FontWeights.Light" />
<!--400-->
<x:Static
Member="FontWeights.Normal" />
<!--500-->
<x:Static
Member="FontWeights.Medium" />
<!--600-->
<x:Static
Member="FontWeights.SemiBold" />
<!--700-->
<x:Static
Member="FontWeights.Bold" />
<!--800-->
<x:Static
Member="FontWeights.ExtraBold" />
<!--900-->
<x:Static
Member="FontWeights.Heavy" />
<!--950-->
<x:Static
Member="FontWeights.ExtraBlack" />
答案 3 :(得分:1)
最后一个,我想:
<ComboBox Name="FontSizes">
<ComboBoxItem Content="8" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="9" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="10" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="11" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="12" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="14" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="16" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="18" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="20" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="22" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="24" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="26" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="28" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="36" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="48" HorizontalContentAlignment="Right"/>
<ComboBoxItem Content="72" HorizontalContentAlignment="Right"/>
</ComboBox>
我搜遍了互联网,但无法找到如何获得标准的字体大小列表。似乎我们必须对其进行硬编码。