2009-04-23 59 views
1

我已經將TypeConverterAttribute屬性應用於我的WPF FrameworkElement子類上的屬性。該屬性的類型是BitmapSource。爲什麼我的TypeConverter沒有被調用?

但TypeConverter永遠不會被創建或調用。這是因爲在ImageSource上指定的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)' 

回答

2

我已經遇到了在此之前,並忽略了它,因爲我已經擁有了一流的豪華被轉換。不過,我剛試過這個,可以確認according to MSDN應該的工作。這就是說,它當然好像不是的工作。

我在WPF Disciples forum上提出這個問題,我也提供了一個解決方法。

-2

你在XAML中的綁定使用它來創建轉換對象。退房this article

<local:MyConverter key="myconverterorsomething"/> 

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

這是一個價值轉換器。我試圖調試TypeConverter階段,所以我試圖設置TypeConverter。 – mackenir 2009-04-23 16:31:35

+0

MSDN example:http://msdn.microsoft.com/en-us/library/bb546926.aspx – 2009-04-23 16:44:36

相關問題