Load content from a dynamically loaded module with MEF - silverlight

I'm working on a modular Silverlight application and in one of the modules I'd like to display an image on a view. I've added the image file under the module project in the /Resources/Images directory. And than I've changed the image file's Build Action property to Content. I think it's nicer not to embed the image into the dll file. The xap file after build contains the image.
In the View xaml I've inserted the image <Image Source="/Resources/Images/Yoda.jpg" /> and design time it displays correctly but runtime the image is missing.
My question is how to solve this problem? I don't want to embed in the dll (Build Action: Resource).
I've made a small test solution if you want to play with it:
Solution.zip
Thanks in advance
Design time the image displayed correctly:
But runtime the image is missing:
Solution structure:

You could set the Copy to Output Directory property of the image to either:
Copy always, or
Copy if newer
Then at runtime it will be available.

Related

Add data file in CSS & Undesired files

Two questions:
What are the steps to add a data file to theme.res in a css activated project? When I open the generated theme.res with the resourceEditor, I can see the data file but the code Resources.getGlobalResources().getData("datafile") returns null.
I keep having some multi-image files "SideCommand*.png" from Resources.getGlobalResources() that I have no idea where they are from since they do not appear in the generated theme.res loaded in resourceEditor.
It could sound like the process is broken somewhere or I do not check out the right theme.res but adding an image to the css area works just fine. I can see it in the resource Editor and I can load it using Resources.getGlobalResources().getData("imagefile"). I'm really lost here, any chance you can guide me?
Cheers.
Emmanuel
If you define a border that can't be satisfied by the existing borders in Codename One the CSS plugin generates a 9-piece border for you by using the JavaFX HTML engine to render the CSS and grab a screenshot. That means the css for SideCommand uses a fancy border.
The CSS processor supports images but not data files at this time. You can add an image using this approach: https://www.codenameone.com/blog/using-css-to-import-images.html
Notice you can add additional res files for data.

Embed image into exe

I see that Blend 4 is not embedding the image to the EXE as WPF does. WPF will create "/my_project;component/Images" and the image will refer to its component. While inserting image in Blend, it will create "pack://siteoforigin:,,," . Only file with size 250KB above will save the image to EXE. How to do this to every image?
Motive: When I go to production, I need to copy the debug folder. But the image is not placed in the running directory, instead in the solution. So running the debug only will result in a system crash as it cannot found the image.
Question: How to make Blend save every image to the EXE or by mean, the application component?

image file resources to image source in silverlight app

I want a Listbox that lists all the images I have as resources in my app, then on selection changed the Image Source in my app is changed.
Need to:
Enumerate all the image files,
Load them into an imagesource
In WPF, I can just System.IO to grab the files from a directory, but I can't do this in silverlight.
how do I do this?
Don't think you can do that for files set as Resource or Content. It is possible for Embedded Resource (although Embedded Resource is not recommended for Silverlight. Don't think that an Image control can access them directly). See related discussion It suggests creating such a list during build time using T4

Show pdf inside silverlight application. PDF to XAML

I need to create silverlight application where customer will see some pdf files.
PDF files have to be inside silverlight control and not rendered as images (customer wants to select text)
For this purposes i need some free libriaries or code to convert pdf file to xaml (or just open pdf so i can convert it to xaml).
Which library can read pdf and help me to convert data to xaml?
Can I read somehow pdf file and write custom convertation tool?
I saw iTextSharp. Is this library can read pdf and help me with my issue?
I will be thankfull for any ideas or links.
I make use of the Acrobat Reader plugin to do the displaying for me. It does require a different method depending on whether your application is running inside or outside the browser (I check if the application is running inside the browser and change the means of display accordingly). If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/9781430272076/.
Hope this helps...
Chris

Why does the Image element give me a design-time error with "add as link"ed images?

I need to display an image, which I've done without problems before, but today I decided to be tricky and use "add as link" instead. Well, now I get:
The file Images/hello.png is not part of the project or its 'Build Action' property is not set to 'Resource'.
Wait... its Build Action is set to Resource. I've seen a Silverlight solution that involves the usage of Merged Dictionaries to share files between Silverlight and WPF projects, but it's not clear to me that this would even apply to my WPF + Image issue.
Has anyone solved this problem before? I could make copies of all of the images, but that seems a little silly if I have a shared repository with clip art and the like.
Dave,
I've just tried to add image as a link to plain WPF application. Build action is "Resource" (don't confuse with "Embedded Resource"). I've added it to the root, and refer to it as <Image Source="/file_name.jpg"/> - all works fine.
The message you have is it compile or runtime? If it's a runtime, how do you refer to the image? Do you see it in Reflector, when you open your assembly (it should be under Resources folder)?
I have images in one assembly which I want to share into another. I've used Add as Link in my second assembly. In the project where the actual image files are located they are in a Resources\Images folder. In the project which links to those files the links are also in a Resources\Images folder. At runtime a XamlParseException claiming "cannot locate resource" is thrown.
My xaml which is referencing the image is in a UserControls folder.
In the project which actually contains the images the path ..\Resources\Images\Blah.png works fine as expected.
Opening the DLLs in Reflector makes it obvious that in the assembly with the linked images holds the images at the root level - the compiler is not respecting the folder location. So in the project with the linked files I have to use ..\Blah.png to find the resource.
Surely a bug in the compiler?

Resources