【发布时间】:2011-08-19 09:33:16
【问题描述】:
我想创建一个 WPF 转换器以根据布尔值返回特定图像。
到目前为止,我得到了以下代码:
return (bool) value
? new BitmapImage(new Uri("pack://application:,,,MyApp.ApplicationResources;component/Resources/image1.png", UriKind.Absolute))
: new BitmapImage(new Uri("pack://application:,,,MyApp.ApplicationResources;component/Resources/image2.png", UriKind.Absolute));
但是这给了我一个例外
System.Windows.Markup.XamlParseException occurred
Message=The URI prefix is not recognized.
图像位于文件夹“资源”中的 MyApp.ApplicationResources 的引用程序集中,并且两者都设置为内容类型:资源。
如果我在 xaml 中图像的源属性中使用相同的 URI,它可以正常工作!
有什么想法吗? 谢谢
【问题讨论】:
-
您尝试过不使用 UriKind.Absolute 吗?我使用完全相同的语法,而且效果很好。
标签: c# wpf uri ivalueconverter