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
- GridViewCancelEditEventArgs.cs
- DataGridViewControlCollection.cs
- AbstractExpressions.cs
- DigestTraceRecordHelper.cs
- PolyQuadraticBezierSegment.cs
- NativeMethods.cs
- ObjectToken.cs
- MenuItem.cs
- SerializationSectionGroup.cs
- TcpHostedTransportConfiguration.cs
- _NtlmClient.cs
- CustomAttribute.cs
- DnsEndPoint.cs
- CapabilitiesUse.cs
- ConfigurationStrings.cs
- CodeGeneratorOptions.cs
- TableProviderWrapper.cs
- RotationValidation.cs
- ThreadPool.cs
- Table.cs
- ControlType.cs
- IPPacketInformation.cs
- TypeConverterAttribute.cs
- InstalledFontCollection.cs
- NameValuePair.cs
- TextSerializer.cs
- PopupRoot.cs
- SqlDataReader.cs
- SymbolPair.cs
- _OSSOCK.cs
- DrawingContextWalker.cs
- AssociationSet.cs
- PageWrapper.cs
- ReflectEventDescriptor.cs
- ComponentManagerBroker.cs
- LiteralControl.cs
- CodeTypeParameter.cs
- SimpleTextLine.cs
- ToolboxComponentsCreatingEventArgs.cs
- SimpleTableProvider.cs
- IList.cs
- HMACSHA256.cs
- MetadataItemEmitter.cs
- Regex.cs
- SemanticResultKey.cs
- BindableTemplateBuilder.cs
- ContainsSearchOperator.cs
- _SingleItemRequestCache.cs
- TypedServiceOperationListItem.cs
- PlatformNotSupportedException.cs
- WebPartDeleteVerb.cs
- XmlSchemaComplexType.cs
- Int32Collection.cs
- CompletionCallbackWrapper.cs
- unsafenativemethodsother.cs
- SiteMapPath.cs
- RedirectionProxy.cs
- WebBrowserSiteBase.cs
- IPipelineRuntime.cs
- QuaternionValueSerializer.cs
- Socket.cs
- ListViewItemCollectionEditor.cs
- PackageRelationshipCollection.cs
- DrawTreeNodeEventArgs.cs
- TextEvent.cs
- Viewport2DVisual3D.cs
- DataSource.cs
- TreeNodeStyleCollection.cs
- Activator.cs
- GenericAuthenticationEventArgs.cs
- BufferedGraphics.cs
- ComplexPropertyEntry.cs
- TypeExtension.cs
- GPPOINT.cs
- PartialClassGenerationTask.cs
- ObjectListGeneralPage.cs
- SmiRequestExecutor.cs
- XmlSchemaAttributeGroupRef.cs
- PkcsUtils.cs
- TextModifierScope.cs
- WindowsEditBoxRange.cs
- Item.cs
- ExtentJoinTreeNode.cs
- InfoCardKeyedHashAlgorithm.cs
- WebPartExportVerb.cs
- TypeReference.cs
- ObjectItemCollection.cs
- WmpBitmapDecoder.cs
- Console.cs
- NullRuntimeConfig.cs
- RegexCompiler.cs
- FillErrorEventArgs.cs
- BrushConverter.cs
- PropertyContainer.cs
- EncryptedKey.cs
- MimeMapping.cs
- PersonalizationStateInfoCollection.cs
- VirtualPath.cs
- HtmlLiteralTextAdapter.cs
- Propagator.Evaluator.cs