![](/img/trans.png)
[英]c# wpf change DoubleAnimation “To” when load (in <Window.Resources>)
[英]WPF c# - cannot load file .resources
啟動我的wpf應用程序並嘗試顯示特定控件,我收到此異常:
“ FileNotFoundException-無法加載文件或程序集“ Xceed.WPF.Toolkit.resources,版本= 2.0.0.0,Culture = it-IT ....”。
我知道這似乎是已經討論過的問題,但是我的問題更加具體。
我有與插件系統一起使用的應用程序(Wolf.exe)。 插件系統從位於擴展應用程序文件夾內的外部dll加載插件類(此文件夾位於.exe的同一級別)。 插件能夠加載額外的資源,例如xaml詞典,並指定自定義樣式以擴展基本組件。
此插件/程序集(FSMExtension.dll)之一以這種方式加載額外的xaml資源:
FileStream oFileStream = new FileStream(filename, FileMode.Open);
if (oFileStream != null)
{
ResourceDictionary oResourceDictionary = (ResourceDictionary)XamlReader.Load(oFileStream);
if (oResourceDictionary != null)
{
Application.Current.Resources.MergedDictionaries.Add(oResourceDictionary);
}
}
oFileStream.Close();
FSMExtension.dll依賴於“擴展的WPF Toolkit™社區版”( http://wpftoolkit.codeplex.com/documentation ),因為它需要一個PropertyGrid組件。 產生的xaml具有相似的方面:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:WolfLib.UI.Converters;assembly=WolfLib"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid;assembly=Xceed.Wpf.Toolkit">
<converters:BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" IsHidden="false" TriggerValue="false"></converters:BooleanToVisibilityConverter>
<Style x:Key="FSMBlockStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<xctk:PropertyGrid Grid.Row="5" Grid.ColumnSpan="2" Margin="5 0 5 5" Visibility="{Binding ElementName=PropertyToggleButton, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}"
ShowSummary="false"
IsCategorized="true"
ShowAdvancedOptions="false"
IsReadOnly="false"
ShowSortOptions="false"
ShowSearchBox="false"
ShowTitle="false"
AutoGenerateProperties="false"
MaxWidth="300">
<xctk:PropertyGrid.PropertyDefinitions>
<xctk:PropertyDefinition TargetProperties="Name,Type,MainController,Views,ControllerBehaviours,ControllerParams"/>
</xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
當我將特定樣式應用於控件時,會收到上述異常。 如果我嘗試直接在我的應用程序內(在MainWindow.xaml上)使用PropertyGrid控件,則不會發生此異常。 這個問題也很奇怪,因為我沒有用於該程序集的任何.resources.dll文件。
我發現解決該問題的唯一方法是為“ Extended WPF Toolkit™Community Edition”指定默認的區域性程序集並重新生成它。
此修復程序適用於使用“ it-IT”語言/區域性的計算機配置。 如果我在具有不同區域性(即en-US)的其他計算機上啟動應用程序,則將再次引發異常。
有沒有解決此類問題的特定方法? 如果您需要更多信息,請與我們聯系。
我不清楚Xceed的工作原理,但是在使用多種區域性時,必須對程序集進行修飾以指示默認區域性。 否則,.NET運行時將抱怨無法找到資源文件。 對於每個使用的程序集,它都放在AssembyInfo.cs
中:
在桌面應用程序中,NeutralResourcesLanguageAttribute屬性將應用程序的默認區域性及其資源位置通知資源管理器。 默認情況下,資源嵌入在主應用程序集中,您可以按如下方式使用該屬性。
聲明看起來像這樣...
[assembly: NeutralResourcesLanguage("en-GB")]
其中“ en-GB”指定默認值。 如果您找不到它,則裝配的裝飾看起來像這樣...
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MultiLanguage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MultiLanguage")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en-GB")]
該文檔位於http://msdn.microsoft.com/zh-cn/library/system.resources.neutralresourceslanguageattribute.aspx
這里有一個WPF參考應用程序,其源代碼為https://tcimultilanguage.codeplex.com/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.