Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have folder called images which contains images needed for my WPF app.
Now I want to use them as resource from XAML and from Runtime.

Is it possible, if yes how (MVVM way) ?

Thanks :)
Posted
Updated 23-Oct-17 22:05pm

1 solution

You just need to set your image's build action to Resource in properties, then you can refer to them as normal
a. in code
C#
public Image MyIcon
{
    get
    {
        return new Bitmap(@"images\yourImage.bmp");
    }
}


b. in XAML
HTML
Icon="Images\yourIcon.ico"
 
Share this answer
 
v2
Comments
cCoderNN 19-Mar-12 5:47am    
Thanks but i want to use resource as ImageSource object not Image
Wayne Gaylard 19-Mar-12 5:55am    
It's the same thing just use something like this - yourBrush.ImageSource =
new BitmapImage(
new Uri(@"Images\yourImage.jpg", UriKind.Relative)
);
CodeMe123 21-Jun-15 15:16pm    
this would be a good solution if he'd asked about using resources and not embedded resources

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900