Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 为什么我的类型转换器没有被调用?_Wpf_Typeconverter - Fatal编程技术网

Wpf 为什么我的类型转换器没有被调用?

Wpf 为什么我的类型转换器没有被调用?,wpf,typeconverter,Wpf,Typeconverter,我已将TypeConverterAttribute属性应用于WPF FrameworkElement子类的属性。属性的类型为BitmapSource 但是类型转换器从未被创建或调用。这是因为ImageSource上指定的TypeConverter优先吗 我正在调试一个数据绑定问题。错误消息从未提及我的TypeConverter类,表明将属性添加到属性没有任何效果: System.Windows.Data Error: 6 : 'TargetDefaultValueConverter' conve

我已将TypeConverterAttribute属性应用于WPF FrameworkElement子类的属性。属性的类型为BitmapSource

但是类型转换器从未被创建或调用。这是因为ImageSource上指定的TypeConverter优先吗

我正在调试一个数据绑定问题。错误消息从未提及我的TypeConverter类,表明将属性添加到属性没有任何效果:

System.Windows.Data Error: 6 : 'TargetDefaultValueConverter' converter failed to convert value '../SmallItemIcons/Gallery.png' (type 'String'); fallback value will be used, if available. BindingExpression:Path=SmallImage.ImageUri; DataItem='ItemSettings' (HashCode=32104365); target element is 'Bitmap' (Name=''); target property is 'Source' (type 'BitmapSource') IOException:'System.IO.IOException: Cannot locate resource 'smallitemicons/gallery.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.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)'

您必须在xaml中创建convert对象,才能在绑定中使用它。退房


我以前遇到过这个问题,并忽略了它,因为我有幸拥有正在转换的类。然而,我刚刚尝试了这个,可以确认它应该是有效的。尽管如此,它显然似乎不起作用


我在上提出了这个问题,在这里我还提供了一个解决方法。

这是一个值转换器。我正在尝试调试TypeConverter阶段,因此我正在尝试设置TypeConverter。这是一个TypeConverter属性附加到正在转换的类型而不是属性的示例-我在某处读到您可以将属性附加到属性。后一种用法就是我要做的。(因为我无法重写BitmapSource类)谢谢,我会关注这个线程。事实上,我会密切关注这个论坛!注意:第二个链接应该是
<local:MyConverter key="myconverterorsomething"/>

<TextBlock Text="{Binding Path=TimeOfSale, 
  Converter={StaticResource myconverterorsomething}, 
  ConverterParameter=' \{0:dd-MMM-yyyy hh:mm\}'}" />