将一些字符串绑定到Image

时间:2018-04-23 10:31:45

标签: wpf xaml data-binding

我们有一个WPF项目,在某些时候我们想要显示一个兼容设备列表。设备来自注册表,不同的模块(项目)可以在其中添加库。

最后,我试图将带有图像的字符串绑定到图像的来源:

<Image Source="{Binding Image}"></Image>

目前在&#34; Image&#34;,我是这样的:

"/My.Project.Name;Component/Images/SomeImage.png"

请注意:

  • &#34;图像&#34;是提到的项目中的文件夹
  • &#34; My.Project.Name&#34;只是一个图书馆项目,所以它不是WPF的
  • &#34; SomeImage.png&#34;目前设置为&#34;内容&#34;。

这是我发现我应该使用的,但目前我收到了这个错误:

System.Windows.Data Error: 6 : 'TargetDefaultValueConverter' converter failed to convert value '/My.Project.Name;Component/Images/SomeImage.png' (type 'String'); fallback value will be used, if available. BindingExpression:Path=Image; DataItem='WizardOneChoice`1' (HashCode=56913160); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') IOException:'System.IO.IOException: Cannot locate resource 'images/someimage.png'.
   at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access)
   at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
   at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
   at System.IO.Packaging.PackWebResponse.get_ContentType()
   at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)
   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
   at System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy)
   at System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
   at MS.Internal.Data.TargetDefaultValueConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)
   at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'

我错过了什么?

0 个答案:

没有答案