Use wpf image control to show an image from filesystem

ぃ、小莉子 提交于 2019-12-21 03:20:31

问题


I want to show an image from a file using an wpf image control. The image file resides in the application directory.

<Image Stretch="Fill" Source="dashboard.jpg" />

The file dashboard.jpg should be replaceable during or after deployment. How do I have to add the image to the project and what BuildAction do I have to use to have the image read from the file system rather than any source I cannot change after deployment. What source uri do I have to use?


回答1:


ImageSource imageSource = new BitmapImage(new Uri("C:\\FileName.gif"));    
image1.Source = imageSource;



回答2:


In markup:

<Image Stretch="Fill">
    <Image.Source>
        <BitmapImage UriSource="dashboard.jpg"/>
    </Image.Source>
</Image>


来源:https://stackoverflow.com/questions/4332652/use-wpf-image-control-to-show-an-image-from-filesystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!