简体   繁体   English

预加载资源组装?

[英]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). 我在窗口上有一个组合框,该框使用外部资源程序集为其字体,并且运行非常缓慢(下拉需要7-8秒)。

<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. 当我删除'FontFamily'属性时,组合框将按预期运行。

Is there a better way? 有没有更好的办法? Possibly to preload the resource assembly? 可能要预加载资源程序集?

(Using VS2010 & .Net 4.0, The resource assembly is about 40MB.) (使用VS2010和.Net 4.0,资源集约为40MB。)

In App.xaml: 在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. 这将导致资源在应用程序启动时加载(然后您将“支付”这7-8秒),但是该组合将表现出预期的效果。

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. 您也可以使用StaticResource而不是DynamicResource但是如果程序集的加载太慢,则视图可能在资源可用之前开始初始化,并引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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