简体   繁体   中英

Preload resource assembly?

I have a combo box on a window that uses an external resource assembly for it font and it's operating really slowly (7-8 seconds to pull down).

<ComboBox ItemTemplate="{StaticResource LangComboboxItemTemplate}" 
x:Name="Lang_Cbx" Width="295" ItemsSource="{Binding Locales}" Height="32" 
FontFamily="/FontLibrary;component/Fonts/Font.CompositeFont#Font"
SelectedValue="{Binding CurrentLanguage}"  SelectedValuePath="LocaleId"  
/>

When I remove the 'FontFamily' attribute the combo box operates as expected.

Is there a better way? Possibly to preload the resource assembly?

(Using VS2010 & .Net 4.0, The resource assembly is about 40MB.)

In App.xaml:

<Application.Resources>
    <FontFamily x:Key="FontFamilyComboBox">/FontLibrary;component/Fonts/Font.CompositeFont#Font</FontFamily>
</Application.Resources>

In the view:

FontFamily="{DynamicResource FontFamilyComboBox}"

This will cause the resource to be loaded at application startup (you'll "pay" those 7-8 seconds then) but the combo will behave as expected.

You can also use StaticResource instead of DynamicResource but if the loading of the assembly is so slow the view might start initialization before the resource is available and cause an exception to be thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM