Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 452
Hardik Avatar asked Mar 13 '13 05:03

Hardik


People also ask

How do I use resource image in WPF XAML?

Set your Image source like this: <Image Source={Binding {x:Static UI:Resources. Search}} /> where 'Search' is name of the resource. Save this answer.

What are resources in WPF?

A resource is an object that can be reused in different places in your application. WPF supports different types of resources. These resources are primarily two types of resources: XAML resources and resource data files. Examples of XAML resources include brushes and styles.


1 Answers

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}" />
like image 162
sa_ddam213 Avatar answered Oct 23 '22 16:10

sa_ddam213