在WPF应用程序的Resources中设置Image source [英] Set Image source from Resources in WPF application

查看:1658
本文介绍了在WPF应用程序的Resources中设置Image source的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何在XAML中从资源中设置源图像。目前我已经

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

 <Image x:Name="img" Panel.ZIndex="1" Source="D:\Img100.jpg"  Stretch="Uniform"/>

我希望Image Source来自Resources。

I want Image Source to be come from Resources.

谢谢。

推荐答案

首先,你必须在项目中包含 BuildAction 资源

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(或其他资源字典)

App.xaml (or other resource dictionary)

<Application.Resources>
    <BitmapImage x:Key="myImage" UriSource="Img100.jpg" />
</Application.Resources>

元素:

<Image Source="{StaticResource myImage}" />

这篇关于在WPF应用程序的Resources中设置Image source的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆