Sunday 15 June 2014

wpf - Unable to load a XAML resource from a project subfolder at design-time -


I used to duplicate the visual model used by a scene in a WPF application on Design Time (Visual Studio 2012, .NET) Has defined 4.5). The visual model refers to an image that is a part of the project material. Unless I have the image in the original project folder, it loads successfully at design time using the URI Conference:

  var Image = new bitmapImage (new URI (@ "pack) : //application:,,,/MyAppAssemblyName;component/MyImage.png "));   

The image has been marked as an embedded resource (I have actually tried to mark it as content and it has been loaded properly).

But I want to use it from the sample project subfolder, so I changed the code above it:

  var image = new bitmap image (new ury (@ " Pack: // application: ,,, / MyAppAssemblyName; component / samples / MyImage .png "));   

Then it stops working, whatever I try (content, embedded resource, etc.), nothing has been loaded from the project's subfolder. This is very strange because I look at the various examples of using subfolders, although I have not found examples of design time. I also tried to use the pack scheme siteforgeon, but then the designer tries to load images from the Visual Studio applications folder.

I

I thought that I was finally found, and this problem Had lied to the character cover. Here is my project structure:

MyProject - Samples - MyImage.png

The following URI works:

  pack: // application:, ,,,, / MyProject; Compponent / samples / MyImage.png   

Do not do this:

  pack: // application: ,,, / MyProject; Component / Samples / MyImage.png Pack: // Application: ,, / MyProject; Component / Samples / myimage.png   

UPDATE After more advice after the Microsoft Forum, I did more tests to restart Visual Studio after every URI change , And my above theory seems to be wrong. Character casing does not matter (all three versions work), but sometimes VS Designer does not catch the recent changes and the VS uses the designer to make the last change. Resume is required.

No comments:

Post a Comment