Code:
/ 4.0 / 4.0 / 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. // 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
- PathNode.cs
- SamlDelegatingWriter.cs
- SafeNativeMethods.cs
- SHA512Cng.cs
- TypeInitializationException.cs
- UmAlQuraCalendar.cs
- PackageProperties.cs
- EncoderExceptionFallback.cs
- CodeMethodInvokeExpression.cs
- StrongNamePublicKeyBlob.cs
- CodeMemberProperty.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Set.cs
- RenderTargetBitmap.cs
- ProfileInfo.cs
- ComplexTypeEmitter.cs
- PenContexts.cs
- HttpCookiesSection.cs
- EncryptedKey.cs
- SqlDataSourceStatusEventArgs.cs
- RuleSettings.cs
- AuthorizationContext.cs
- MatrixCamera.cs
- LinkButton.cs
- BitArray.cs
- XamlVector3DCollectionSerializer.cs
- ManagementEventArgs.cs
- GC.cs
- WindowManager.cs
- Overlapped.cs
- SecurityMode.cs
- BreakSafeBase.cs
- CounterSample.cs
- XslTransform.cs
- ExceptionHandlerDesigner.cs
- AttributeQuery.cs
- GridViewPageEventArgs.cs
- ProbeDuplexCD1AsyncResult.cs
- AccessViolationException.cs
- HyperLinkColumn.cs
- DeadCharTextComposition.cs
- GradientSpreadMethodValidation.cs
- CanonicalXml.cs
- VirtualDirectoryMapping.cs
- BuilderPropertyEntry.cs
- HttpContext.cs
- TypeInfo.cs
- UnaryOperationBinder.cs
- CodeDefaultValueExpression.cs
- SafeNativeMethods.cs
- StyleTypedPropertyAttribute.cs
- ProvideValueServiceProvider.cs
- GetChildSubtree.cs
- TextWriterTraceListener.cs
- Int16AnimationUsingKeyFrames.cs
- Typeface.cs
- CapabilitiesSection.cs
- Encoder.cs
- EntryIndex.cs
- WindowsUpDown.cs
- RuleCache.cs
- DeviceContext.cs
- DeferredElementTreeState.cs
- NumberFormatInfo.cs
- Size3DConverter.cs
- Int32Rect.cs
- RetrieveVirtualItemEventArgs.cs
- MemberAssignmentAnalysis.cs
- CodeExpressionStatement.cs
- SplitterCancelEvent.cs
- LocatorGroup.cs
- SoapIncludeAttribute.cs
- WorkflowApplicationUnloadedException.cs
- DateTimeOffsetConverter.cs
- InputBinding.cs
- UnsafeNativeMethods.cs
- RtType.cs
- DiscoveryEndpoint.cs
- InkCanvasSelection.cs
- EncryptedKey.cs
- CopyNamespacesAction.cs
- SqlDataSourceView.cs
- Filter.cs
- BeginGetFileNameFromUserRequest.cs
- ContractValidationHelper.cs
- PngBitmapEncoder.cs
- AppDomainUnloadedException.cs
- InfoCardBaseException.cs
- GroupQuery.cs
- SerializationInfo.cs
- CatalogZone.cs
- ToolStripItemClickedEventArgs.cs
- remotingproxy.cs
- IisHelper.cs
- NamespaceDecl.cs
- Pkcs7Recipient.cs
- DBSchemaRow.cs
- KnownTypeAttribute.cs
- OutputScopeManager.cs
- ToolStripItemEventArgs.cs