WPF: Embedding Images in the Assembly

Yesterday, I searched for a possiblity to include PNGs into my assemblies and access tem from WPF/XAML. The only stuff I found was Chad Campbell‘s “Point an Image to an Embedded Resource“. Chad recommends using embedded resources and manually extracting them with Assembly.GetManifestResourceStream and PngBitmapDecoder in the code-behind. Yuck! That would mean giving every Image a Name and jump through hoops to share memory and what not. Today I looked at it again and… thought I should be able to create a custom System.Windows.Media.ImageSource using a hidden BitmapSource for XAML usage. Far from it! While ImageSource is public abstract, it uses some “private parts” from Windows.Media.Composition.DUCE which are not available to the common folk. Finally uncle google came to the rescue: in a microsoft forum posting (“Using Bitmap resources from .resx file in WPF“) Ashish Shetty explains how to use a special URI syntax to access resources directly from XAML. The catch is that the images have to be built as “Resource” and not as “Embedded Resource“. This seems to be only available if the assembly was created from one of the WPF project templates[1]. But if everything is done right, the resource can be accessed by simply setting the “Source” property:

<!-- local assembly -->
<image Source="/directory/foo.png" />
<!-- referenced assembly -->
<image Source="/AssemblyName;component/directory/foo.png" />

More details can be found in the MSDN article “Windows Presentation Foundation Application Resource, Content, and Data Files“. [1] See the last comment at How to use resources (images) in dll assembly?

dasZ.at

dasZ.at - the people behind ZBox.
dasZ.at Logo

Downloads

The lateset download will be available here - soon

Lastet blog

In our blog we talk about the latest developments around our tool ZBox.
>> Blog

Latest blog entries
>> Reference project: Implementing WordPress-based Website

Based on the reference design provided by Sabine herself, we implemented the zartbitter Website. The site is powered by the PHP-based WordPress blog and CMS engine, some additional plugins and a bit of yarn to hold it all together.


>> Setting a permanent search_path, the Right Way

Others recommend setting the search_path in the postgresql.conf. Current versions of PostgreSQL can set the search_path permanently on a per-database basis without having to touch system configuration files


>> Porting Puppet to Windows

In the course of the PuppetCamp Europe, I met with many people I only knew from IRC and email and it was a great time with interesting and inspiring discussions.

Today I want to write about the work I’m currently commisioned for by puppetlabs, porting puppet to Microsoft Windows.


>> Puppetcamp Europe 2010

I’m going to Puppetcamp Europe 2010!


>> Using gendarme with Code Contracts from .NET 4.0

When using gendarme on post-processed assemblies with code contracts and /throwonfailure set, a few things have to be ignored. Put the following lines into your ignore file (for example gendarmeignore.txt) and use it with –ignore on the command line.


>> Microsoft cannot decode Base64: News at 11!

Arthur has found a really nasty bug in Microsoft’s streaming Base64 decoder as used in the WCF: Connect Bug#541494


>> Kolab Connector binaries uploaded

Arthur moved on with programming and testing. Now we uploaded the first packages, which now contain the basic calendar and contacts synchronisation. The plugins already are able to synchronize our personal data.


>> Kolab Sync for Android and Outlook: Developer Preview

We are proud to announce the first developer preview for Kolab sync clients for both Android and Outlook. Both are licensed under the GPLv3.


>> Visual Studio 2008 Debugger

I didn’t know that: the VS2008 debugger has many bugs. Specifically, if you have a solution with multiple websites, debugging doesn’t work!

Symptom: Upon reaching a breakpoint, StepOver/Into do not work, but resume execution. This makes the debugger pretty pointless.


>> Building a simple MSBuild Task

On the “Using Studio’s “Custom Tool” in MSBuild” question, I was prompted to share the code. Here is a stripped down skeleton where I removed the actual calls to the custom tool. Since it is open source I didn’t really need to access the Visual Studio’s registry keys.