Set Image source from Resources in WPF application

后端 未结 1 1694
故里飘歌
故里飘歌 2020-12-28 20:04

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

 

        
相关标签:
1条回答
  • 2020-12-28 20:48

    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}" />
    
    0 讨论(0)
提交回复
热议问题