Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Toolbox / ToolboxItemImageConverter.cs / 1484997 / ToolboxItemImageConverter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Activities.Presentation.Toolbox { using System; using System.Drawing; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; //This class is responsible for converting 'old' bitmap style, contained //in ToolboxItem objects to WPF compatible ImageSource object [ValueConversion(typeof(Bitmap), typeof(ImageSource))] sealed class ToolboxItemImageConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { Bitmap source = value as Bitmap; if (targetType == typeof(ImageSource) && null != source) { IntPtr hBitmap = source.GetHbitmap(); try { BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions(); return Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions); } finally { System.Activities.Presentation.View.Win32Interop.DeleteObject(hBitmap); } } return null; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw FxTrace.Exception.AsError(new NotSupportedException()); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Activities.Presentation.Toolbox { using System; using System.Drawing; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; //This class is responsible for converting 'old' bitmap style, contained //in ToolboxItem objects to WPF compatible ImageSource object [ValueConversion(typeof(Bitmap), typeof(ImageSource))] sealed class ToolboxItemImageConverter : IValueConverter { object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { Bitmap source = value as Bitmap; if (targetType == typeof(ImageSource) && null != source) { IntPtr hBitmap = source.GetHbitmap(); try { BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions(); return Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions); } finally { System.Activities.Presentation.View.Win32Interop.DeleteObject(hBitmap); } } return null; } object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw FxTrace.Exception.AsError(new NotSupportedException()); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SafeWaitHandle.cs
- TableCellCollection.cs
- PrimaryKeyTypeConverter.cs
- DirectoryInfo.cs
- WebPartsPersonalization.cs
- ToolboxItemAttribute.cs
- MaterialGroup.cs
- SqlNamer.cs
- HeaderFilter.cs
- SqlDataSourceConfigureSelectPanel.cs
- WebSysDisplayNameAttribute.cs
- OracleDataAdapter.cs
- TextServicesCompartmentContext.cs
- VisualStateGroup.cs
- RadioButton.cs
- TextEvent.cs
- TableRow.cs
- WarningException.cs
- GradientStop.cs
- DesignerActionItemCollection.cs
- SimpleBitVector32.cs
- WindowsListViewScroll.cs
- Peer.cs
- MachineKeySection.cs
- Empty.cs
- ClientSettings.cs
- DataGridAddNewRow.cs
- HttpContextServiceHost.cs
- AnnotationHelper.cs
- MetadataFile.cs
- XmlAttributeOverrides.cs
- HitTestWithPointDrawingContextWalker.cs
- CompositeFontParser.cs
- DependencyObjectPropertyDescriptor.cs
- FusionWrap.cs
- OleDbStruct.cs
- baseaxisquery.cs
- SafeEventLogWriteHandle.cs
- NonVisualControlAttribute.cs
- MouseEvent.cs
- StandardOleMarshalObject.cs
- ServiceNameElement.cs
- Timeline.cs
- NumericUpDown.cs
- QuotedPrintableStream.cs
- GridEntry.cs
- BuildProviderCollection.cs
- MaterializeFromAtom.cs
- TagMapCollection.cs
- PrintDialog.cs
- SplineQuaternionKeyFrame.cs
- ProjectionPath.cs
- ElementHostPropertyMap.cs
- ObjectMemberMapping.cs
- BitSet.cs
- SamlNameIdentifierClaimResource.cs
- CacheOutputQuery.cs
- ConfigurationManagerInternalFactory.cs
- ConfigurationUtility.cs
- XMLUtil.cs
- ContainsRowNumberChecker.cs
- DataBindingHandlerAttribute.cs
- ExceptionRoutedEventArgs.cs
- StringCollection.cs
- KeyValueSerializer.cs
- WindowsFormsHelpers.cs
- ToolBarButtonClickEvent.cs
- ScriptReferenceEventArgs.cs
- BrowserCapabilitiesCodeGenerator.cs
- ScrollProviderWrapper.cs
- FontCollection.cs
- _FtpDataStream.cs
- ConstraintCollection.cs
- ModifiableIteratorCollection.cs
- DataRecordInternal.cs
- TabletCollection.cs
- GridErrorDlg.cs
- CompensationTokenData.cs
- ListBox.cs
- ImageSourceValueSerializer.cs
- ellipse.cs
- WebPartConnectionsCancelVerb.cs
- MemoryPressure.cs
- ButtonColumn.cs
- HttpAsyncResult.cs
- ProviderConnectionPointCollection.cs
- SettingsSection.cs
- EditorBrowsableAttribute.cs
- TagMapInfo.cs
- WindowsHyperlink.cs
- XmlBinaryReader.cs
- ListViewSortEventArgs.cs
- Fx.cs
- PropertyStore.cs
- LineInfo.cs
- TypeExtensionConverter.cs
- KnownTypes.cs
- DataViewSetting.cs
- RegionIterator.cs
- MembershipSection.cs