Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display image from resources by binding -WPF

I have an icon on resources that it key is: xxx

I want to bind it to an image in xaml..

1:

  <Image Source="{x:Static p:Resources.xxx}"></Image>

2:

  <Image>
     <Image.Source>
         <BitmapImage UriSource="{Binding x:Static p:Resources.xxx}"/>
        </Image.Source>
   </Image>

3:

 <Image Source=" {Binding x:Static p:Resources.xxx,Converter={StaticResource IconToBitmap_Converter}}"></Image>

4:

 <Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding x:Static p:Resources.xxx,Converter={StaticResource IconToBitmap_Converter}}"/>
    </Image.Source>
 </Image>

The above ways does not work, how am I supposed to do that?

like image 394
Hodaya Shalom Avatar asked Feb 07 '13 12:02

Hodaya Shalom


1 Answers

First you must add your Image into a Resource File in the Solution Explorer. Next you must set the Build Action of your Image to Resource and then you can use it in the XAML Code like this:

<UserControl>
<UserControl.Resources>
    <ResourceDictionary>
        <BitmapImage x:Key="name" UriSource="Resources/yourimage.bmp" />
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <Image  Source="{StaticResource name}"/>
</Grid>
</UserControl>
like image 188
user2025830 Avatar answered Sep 20 '22 03:09

user2025830