Load image from Assembly

If you create a new CustomControl and want to load an image from the resources you can use this method.
Because in CustomContorls you can not load the image with the path, therefore you have to load it directyl from the assembly.

public static BitmapImage getImageFromAssembly(string filename)
  var path = string.Format("/MyAssembly;component/{0}", filename);
  var uri = new Uri(path, UriKind.Relative);
  var resourceStream = Application.GetResourceStream(uri);
  if (resourceStream == null)
    return null;

  var bitmap = new BitmapImage();
  bitmap.StreamSource = resourceStream.Stream;
  return bitmap;
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: