繁体   English   中英

在代码后面设置WPF图像控件的源

[英]Setting the source of WPF Image control behind code

最近,我一直在努力在代码内部设置“设置WPF Image控件的来源”。

我已经尝试过类似的东西:

Image.Source = new BitmapImage(new Uri(@"/hrc.Hands;component/Images/BlueFolder.png", UriKind.RelativeOrAbsolute));

但这似乎不起作用,并且没有将对象引用设置为对象异常的实例。 这是我的图像在hierachy中的路径的屏幕截图:

在此处输入图片说明

您可以使用..

var imageSource = new Uri(@"pack://application:,,,/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/" + "Images/BlueFolder.png", UriKind.Absolute);
Image.Source = imageSource;

另外,请确保将BlueFolder.png设置为Resource 右键单击图像,然后选择“ Properties以执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM