WPF ComboBox Font Binding FileFormatException

I have a Combibox WPF that is bound to

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>

      

The following exception is thrown. What would be the best way to clear the Fonts.SystemFontFamilies of any invalid fonts?

File

': /// File C: / Program Files (x86) / Common Files / Adobe / SING / AssocCache / Generic.otf does not meet expected file format specification.

0


source to share


1 answer


Ok, the following example helped Sample Font Chooser

The following code also excludes character fonts which cannot be used in my situation:



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

      

+1


source







All Articles