开发者

problem loading resource from class library

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.


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>;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜