views:

174

answers:

1

I have two silverlight assemblies, CaseManager.Applet and CaseManager.Applet.Sample. The Sample assembly has a reference to the base Applet assembly. The sample assembly has an embedded resource png image. The base applet assembly has a view xaml that I wish to display that image programmatically.

In the sample assembly I have a bit of code that creates a Uri like so:

var icon = new AppletIcon()
                   {
                     ImageUri = new Uri("CaseManager.Applet.Sample;component/images/guiness_2.png", UriKind.Relative),
                     ModuleType = GetType(),
                     Text = "Sample Module"
                   };

When I execute this code all the properties of ImageUri throw InvalidOperationException. I am not sure why. Anyone have suggestions?

A: 

The following code does the job:

var icon = new AppletIcon()
                   {
                     ImageUri = new Uri("/CaseManager.Applet.Sample;component/images/guiness_2.png", UriKind.Relative),
                     Module = this,
                     Text = "Sample Icon"
                   };

Things to note here:

  • The slash at the start of the Uri string.
  • The short name of the assembly containing the resource.
  • the ;component/ section.

From there it is basically the path inside your project to the image. Hope this helps someone else.

For what it was worth I was missing the very first slash.

NotMyself