我在一个窗口上有一个组合框,它使用了一个外部资源程序集作为字体,它的运行速度非常慢(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"
/>当我删除'FontFamily‘属性时,组合框就会按预期运行。
有没有更好的方法?可能是为了预加载资源程序集?
(使用VS2010 & .Net 4.0,资源程序集大约为40MB。)
发布于 2013-01-10 16:36:06
在App.xaml中:
<Application.Resources>
<FontFamily x:Key="FontFamilyComboBox">/FontLibrary;component/Fonts/Font.CompositeFont#Font</FontFamily>
</Application.Resources>在视图中:
FontFamily="{DynamicResource FontFamilyComboBox}"这将导致资源在应用程序启动时加载(然后您将“支付”这7-8秒),但组合将按预期运行。
您也可以使用StaticResource而不是DynamicResource,但是如果程序集的加载速度很慢,视图可能会在资源可用之前启动初始化,并导致抛出异常。
https://stackoverflow.com/questions/14224682
复制相似问题