WPF ComboBox字体绑定FileFormatException

时间:2009-01-07 04:43:32

标签: wpf vb.net data-binding combobox fonts

我有一个绑定到

的WPF Combobox
Me.fontComboFast.ItemsSource = Fonts.SystemFontFamilies


<ComboBox x:Name="fontComboFast">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" FontFamily="{Binding}" FontSize="15" Height="20"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

发生以下异常。如何清除任何无效字体的Fonts.SystemFontFamilies的最佳方法是什么?

'file:/// C:/ Program Files(x86)/ Common Files / Adob​​e / SING / AssocCache / Generic.otf'文件不符合预期的文件格式规范。

1 个答案:

答案 0 :(得分:1)

好的,以下示例帮助Sample Font Chooser

以下代码也排除了在我的情况下无法使用的符号字体:

Friend Function IsSymbolFont(ByVal FontFamily As FontFamily) As Boolean
    For Each typeface As Typeface In FontFamily.GetTypefaces()
        Dim Face As New GlyphTypeface

        Try
            If typeface.TryGetGlyphTypeface(Face) Then
                Return Face.Symbol
            End If
        Catch e As Exception
            Return True
        End Try

    Next
    Return False
End Function