Display image from resources by binding -WPF

I have an icon on the resources it has: 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 methods don't work, how should I do it?

+3


source to share


1 answer


First you have to add your image to the resource file in the solution explorer. Then you have to set the build action of your image to the resource, and then you can use it in XAML like this:



<UserControl>
<UserControl.Resources>
    <ResourceDictionary>
        <BitmapImage x:Key="name" UriSource="Resources/yourimage.bmp" />
    </ResourceDictionary>
</UserControl.Resources>
<Grid>
    <Image  Source="{StaticResource name}"/>
</Grid>
</UserControl>

      

+10


source







All Articles