Hardik
Hardik

Reputation: 1764

Set Image source from Resources in WPF application

Can anyone show me how can I set source to image from Resource in XAML. Currently I have

 <Image x:Name="img" Panel.ZIndex="1" Source="D:\Img100.jpg"  Stretch="Uniform"/>

I want Image Source to be come from Resources.

Thanks.

Upvotes: 14

Views: 38455

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43596

First you will have to include the image in your project with BuildAction Resource

Then you can use it directly in your Image

 <Image Source="Img100.jpg"/>

Or make a reusable resource of the image

App.xaml (or other resource dictionary)

<Application.Resources>
    <BitmapImage x:Key="myImage" UriSource="Img100.jpg" />
</Application.Resources>

Element:

<Image Source="{StaticResource myImage}" />

Upvotes: 33

Related Questions