1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.Activities.Presentation.Toolbox
9 using System.Globalization;
11 using System.Windows.Data;
12 using System.Windows.Interop;
13 using System.Windows.Media;
14 using System.Windows.Media.Imaging;
15 using Microsoft.Tools.Common;
17 //This class is responsible for converting 'old' bitmap style, contained
18 //in ToolboxItem objects to WPF compatible ImageSource object
20 [ValueConversion(typeof(Bitmap), typeof(ImageSource))]
21 sealed class ToolboxItemImageConverter : IValueConverter
23 object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
25 Bitmap source = value as Bitmap;
26 if (targetType == typeof(ImageSource) && null != source)
28 IntPtr hBitmap = source.GetHbitmap();
31 BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
32 return Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
36 Win32Interop.DeleteObject(hBitmap);
42 object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
44 throw FxTrace.Exception.AsError(new NotSupportedException());