开发者

Image source using project resource (WPF)

开发者 https://www.devze.com 2022-12-22 12:55 出处:网络
I added a bunch of images as projec开发者_StackOverflow中文版t resources. Now i want to use them in my WPF application using the image control.

I added a bunch of images as projec开发者_StackOverflow中文版t resources. Now i want to use them in my WPF application using the image control. How can I assign the resource to the source of the image control?


First, mark you image file as a "Resource" in the properties window of Visual Studio. Then you can quite easily reference the resource using the file name:

<Image x:Name="image1" Source="theimage.png" />

If you have put your image in a folder, you can use

<Image x:Name="image1" Source="/folder/theimage.png" />


You wanted to reference your image in XAML right?

like this

<Image Source="Resources\MyImage.png" />

and you dont need to add the image to the project resource. just add the images to your project via solution explorer

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号