Question

I have a WPF Combobox that is binding 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 occurs. How would be the best way to clear the Fonts.SystemFontFamilies of any invalid fonts?

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

Was it helpful?

Solution

Okay, the following sample helped Sample Font Chooser

The following code also excludes symbol fonts that are not usable 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top