Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / EventSetterHandlerConverter.cs / 1305600 / EventSetterHandlerConverter.cs
// Copyright (C) Microsoft Corporation. All rights reserved. using System.ComponentModel; using System.Globalization; using System.Windows; using System.Collections.Generic; using System.Xaml; namespace System.Windows.Markup { ////// Type converter for RoutedEvent type /// public sealed class EventSetterHandlerConverter : TypeConverter { ////// Whether we can convert from a given type - this class only converts from string /// public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType) { // We can only convert from a string and that too only if we have all the contextual information // Note: Sometimes even the serializer calls CanConvertFrom in order // to determine if it is a valid converter to use for serialization. if (sourceType == typeof(string)) { return true; } return false; } ////// Whether we can convert to a given type - this class only converts to string /// public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType) { return false; } ////// Convert a string like "Button.Click" into the corresponding RoutedEvent /// public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { if (typeDescriptorContext == null) { throw new ArgumentNullException("typeDescriptorContext"); } if (source == null) { throw new ArgumentNullException("source"); } IRootObjectProvider rootProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider; if (rootProvider != null && source is String) { IProvideValueTarget ipvt = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; if (ipvt != null) { EventSetter setter = ipvt.TargetObject as EventSetter; string handlerName; if(setter != null && (handlerName = source as string) != null) { handlerName = handlerName.Trim(); return Delegate.CreateDelegate(setter.Event.HandlerType, rootProvider.RootObject, handlerName); } } } throw GetConvertFromException(source); } ////// Convert a RoutedEventID into a XAML string like "Button.Click" /// public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType) { throw GetConvertToException(value, destinationType); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConnectionAcceptor.cs
- ResolveDuplexCD1AsyncResult.cs
- MetaColumn.cs
- RuntimeWrappedException.cs
- DataFormats.cs
- XslNumber.cs
- MasterPageBuildProvider.cs
- LinqDataSourceStatusEventArgs.cs
- EFTableProvider.cs
- FixedDocumentPaginator.cs
- ResourceDescriptionAttribute.cs
- TextElement.cs
- XmlWrappingReader.cs
- TraceHandlerErrorFormatter.cs
- METAHEADER.cs
- WindowsFormsSynchronizationContext.cs
- odbcmetadatacolumnnames.cs
- TextTreeObjectNode.cs
- CompositeClientFormatter.cs
- InstanceKeyNotReadyException.cs
- Pick.cs
- Compilation.cs
- LogEntrySerialization.cs
- ToolboxComponentsCreatingEventArgs.cs
- NamedObject.cs
- MetadataCollection.cs
- ResourceExpression.cs
- JavaScriptString.cs
- SettingsSection.cs
- DatePickerTextBox.cs
- VirtualDirectoryMapping.cs
- Themes.cs
- XamlSerializerUtil.cs
- SimpleFieldTemplateUserControl.cs
- Types.cs
- SqlServices.cs
- SpnEndpointIdentity.cs
- CngKeyBlobFormat.cs
- ShapeTypeface.cs
- CheckPair.cs
- TypeConverterHelper.cs
- TraceUtility.cs
- BinaryObjectReader.cs
- FormatterServices.cs
- ApplicationTrust.cs
- CompiledQuery.cs
- ToolboxCategory.cs
- XPathCompileException.cs
- OpCodes.cs
- DataContext.cs
- DataGridViewColumnConverter.cs
- SchemaImporter.cs
- WebControlAdapter.cs
- CustomAttributeFormatException.cs
- Timer.cs
- BasicCellRelation.cs
- Point3DCollection.cs
- CodeArrayCreateExpression.cs
- GlyphCache.cs
- StringUtil.cs
- RadioButton.cs
- StatusStrip.cs
- RangeValuePattern.cs
- EnumConverter.cs
- WebPartCloseVerb.cs
- StylusPointPropertyInfo.cs
- CustomPopupPlacement.cs
- HtmlInputFile.cs
- PlanCompilerUtil.cs
- TraceFilter.cs
- DataTable.cs
- DSASignatureFormatter.cs
- TraceHandler.cs
- Assembly.cs
- TcpTransportSecurityElement.cs
- PriorityRange.cs
- EntityDataSourceDesigner.cs
- SmtpReplyReader.cs
- Viewport3DAutomationPeer.cs
- CroppedBitmap.cs
- ExtractedStateEntry.cs
- GroupItem.cs
- ConditionCollection.cs
- HttpException.cs
- OpCodes.cs
- WindowsToolbarAsMenu.cs
- CodeGenHelper.cs
- MethodAccessException.cs
- AppSettingsSection.cs
- PropertyEmitter.cs
- OdbcCommand.cs
- XMLSchema.cs
- EventHandlerService.cs
- BitmapEffectGeneralTransform.cs
- MessageSmuggler.cs
- DeploymentSectionCache.cs
- Vector3DCollection.cs
- Positioning.cs
- ImageClickEventArgs.cs
- OdbcError.cs