tags:

views:

44

answers:

1

I have a class library (mylibrary) which has a resource called "close.png". I used redGate reflector to confirm that the resource is actually present in the dll. Now i use mylibrary.dll in a project where i attempt to extract this "close.png" resource like this :

BitmapImage crossImage = new BitmapImage();   
crossImage.BeginInit();  
crossImage.UriSource = new Uri(@"/mylibrary;component/Resources/close.png", UriKind.RelativeOrAbsolute);  
crossImage.EndInit();

This BitmapImage crossImage is then used like :

Button closeButton = new Button()  
{  
    Content = new System.Windows.Controls.Image()  
    {  
        Source = crossImage  
    },  
    MaxWidth = 20,  
    MaxHeight = 20  
};

On doing this i get no exceptions being thrown but the button shows no image. Also, i do see some exception info if i investigate the button's 'content' in the debugger.

+3  A: 

Is it an embedded resource? (can't make that up from the question)

If so, there's a good tutorial on MSDN

//not tested, but should be like this
BitmapImage = <namespace>.Properties.Resources.<imagename>;
PoweRoy
In the Resources editor there is also a ComboBox called 'Access Modifier' next to the 'Add Resource' button. Set it to *public* to access the resource from another assembly.
Oliver
And then you should use GetAssembly, see more here: http://www.csharper.net/blog/getting_an_embedded_resource_file_out_of_an_assembly.aspx
PoweRoy