gpt4 book ai didi

.net - 将 FontStyles 和 FontWeights 绑定(bind)到 WPF ComboBox

转载 作者:行者123 更新时间:2023-12-02 20:13:29 29 4
gpt4 key购买 nike

我只是想知道是否可以将可用的 FontStyleFontWeight 列表绑定(bind)到 ComboBox

例如,要将字体列表绑定(bind)到组合框,您可以使用:

FontComboBox.ItemsSource = Fonts.SystemFontFamilies;

我还可以买一些东西吗:

FontStyleComboBox.ItemsSource = .... 
FontWeightComboBox.ItemsSource = .... ?

是否需要对 System.Windows.FontWeights 和 System.Windows.FontStyles 类进行反射,或者是否有比这更简单的方法?

谢谢

最佳答案

对于字体系列组合:

<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}"/>

关于.net - 将 FontStyles 和 FontWeights 绑定(bind)到 WPF ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1994696/

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