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.
Set your Image source like this: <Image Source={Binding {x:Static UI:Resources. Search}} /> where 'Search' is name of the resource. Save this answer.
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.
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}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With