繁体   English   中英

WPF 图标和 Uri

[英]WPF Icon and Uri

我正在尝试直接在主目录中加载我项目中的图标。 为了做到这一点,我这样做:

Dim uriSrc As Uri = New Uri("pack://ELE100WalkerWPF:,,,/assemblyName;Component/ShowMCF.png")
Dim bitmapImage As BitmapImage = New BitmapImage With {.UriSource = uriSrc}
Dim image As System.Windows.Controls.Image = New System.Windows.Controls.Image() With {.Source = bitmapImage}

即使对于我的样式我以相同的方式引用它们,这也根本不起作用:

<ResourceDictionary Source="pack://application:,,,/ELE100WalkerWPF;component/Resources/Colors.xaml" />

唯一的区别是我的样式是在 application.xaml 的 MergeDictionary 中定义的,就像这样

<ResourceDictionary Source="Resources/Colors.xaml" />

有人可以解释为什么图像没有显示以及我如何解决这个问题? 提前致谢

pack://ELE100WalkerWPF:...不是有效的Pack URI

您也不能在不调用BeginInitEndInit情况下设置 BitmapImage 的UriSource属性。 使用采用 Uri 参数的 BitmapImage 构造函数。

假设ShowMCF.png位于 Visual Studio 项目的顶级文件夹中,并且其 Build Action 设置为Resource ,这应该可以工作:

Dim uri As Uri = New Uri("pack://application:,,,/ShowMCF.png")
Dim bitmapImage As BitmapImage = New BitmapImage(uri)

如果图像资源位于引用的程序集(称为 ELE100WalkerWPF)中,则必须包含程序集名称,如下所示:

Dim uri As Uri = New Uri("pack://application:,,,/ELE100WalkerWPF;component/ShowMCF.png")
Dim bitmapImage As BitmapImage = New BitmapImage(uri)

暂无
暂无

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

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