I enumerate the list of fontfamilies and bind to combobox, the problem is when there is a font in the system that is corrupted. The whole application will crashes. Any way i am able to bind to systemfontfamilies yet able to skip font that has error displaying?
THe following code runs fine if the fontfamily binding in the itemtemplate is commented.
<ComboBox x:Name="comboFonts"
Grid.IsSharedSizeScope="True"
Grid.Row="0" Grid.Column="1"
ItemsSource="{Binding Source={x:Static Member=Fonts.SystemFontFamilies}}"
SelectedItem="{Binding FontFamily, Mode=TwoWay}"
HorizontalAlignment="Stretch">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="FontName"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Source}" HorizontalAlignment="Left"/>
<Label FontFamily="{Binding FallbackValue=Verdana}" HorizontalAlignment="Right">Sample</Label>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
THe error message that get is as following
Message=Input file or data stream does not conform to the expected file format specification.
Source=PresentationCore
StackTrace:
at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
at MS.Internal.Text.TextInterface.Font.CreateFontFace()
at MS.Internal.Text.TextInterface.Font.AddFontFaceToCache()
at MS.Internal.Text.TextInterface.Font.GetFontFace()
Please help. THanks