|
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
waltersb
Joined: 12 Jun 2012 Posts: 5
|
Posted: Mon Jul 16, 2012 1:00 pm Post subject: Exception "Can not locate resource 'images/...' |
|
|
I have the following problem:
When I switch the culture to a variant culture (en-US) and then load a bitmap the following error occurs:
"Can not locate resource 'images / point_red.png'."
In the invariant culture ("de-DE") everything works correct:
Code: |
private void rbDeutsch_Checked(object sender, RoutedEventArgs e) {
CultureManager.UICulture = new System.Globalization.CultureInfo("de-DE");
Img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/point_green.png")); //works correct
}
private void rbEnglisch_Checked(object sender, RoutedEventArgs e) {
CultureManager.UICulture = new System.Globalization.CultureInfo("en-US");
Img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/point_red.png")); //Exception: Can not locate resource 'images / point_red.png'
}
|
When I insert following attribute switching to the variant culture (en-US) works correct. The image "point_red.png ist displayed correctly:
Code: |
[assembly: NeutralResourcesLanguage("de-DE", UltimateResourceFallbackLocation.Satellite)]
|
But when I insert this attribute, only the resource names (e.g. "#TextBlock_Text1") are dislayed when I switch to the invariant culture "de-DE".
Is this a Globalizer problem? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jul 17, 2012 9:29 am Post subject: |
|
|
This isn't really a Globalizer issue - however the Microsoft documentation on using the NeutralResourcesLanguage attribute is VERY confusing.
You normally do not need to use the attribute - it appears to be used as either a performance optimization (see http://stackoverflow.com/questions/4068360/c-sharp-warning-mark-assemblies-with-neutralresourceslanguageattribute) or to allow you to use a language compiled into a satellite resource as your default fallback language. The Microsoft documentation indicates that you need to manually modify your .csproj file to add a <UICulture> element if you use the attribute (see the following comments from the default assembly info file).
Code: | //In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file. |
If you change this on our sample project and make "fr" the language specified in both the UICulture element and in the NeutralResourceLanguage attribute then the application will use the French resources as the default (ie even when the locale is english).
I would avoid using the NeutralResourceLanguage attribute because it does seem to cause issues.
Rather than loading the images using a URI you can use the Resx Extension (in markup) to actually load images from your Resx file. Simply add the images to your resx file and then set the markup to point at them. The sample WPF project does this with the Window Icon - but you can do the same thing with images. This may get around the problem you are having with the URI not working correctly. _________________ Infralution Support |
|
Back to top |
|
|
waltersb
Joined: 12 Jun 2012 Posts: 5
|
Posted: Tue Jul 17, 2012 1:18 pm Post subject: |
|
|
Thanks for the quick reply.
The whole problem was that I added "<UICulture>de-DE</ UICulture>" in the project files.
Because of that satellite assemblies for the invariant culture "de-DE" were created which caused the problems.
After I removed these entries the loading of bitmaps via
Code: |
Img.Source = new BitmapImage (new Uri (" pack :/ / application:,,, / Images / point_red.png "));
|
worked correct. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|