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
- Int64Storage.cs
- Input.cs
- BmpBitmapEncoder.cs
- ChineseLunisolarCalendar.cs
- FlowPanelDesigner.cs
- bidPrivateBase.cs
- ImageButton.cs
- XamlClipboardData.cs
- MdiWindowListStrip.cs
- HttpConfigurationContext.cs
- HtmlInputImage.cs
- OleDbFactory.cs
- NameScopePropertyAttribute.cs
- ComponentConverter.cs
- PageContentAsyncResult.cs
- ProfileGroupSettingsCollection.cs
- EditBehavior.cs
- XmlEntity.cs
- Utils.cs
- NativeMethods.cs
- DataShape.cs
- RenderTargetBitmap.cs
- AsymmetricAlgorithm.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- WebPartPersonalization.cs
- TreeNodeCollection.cs
- PolyBezierSegment.cs
- GridViewEditEventArgs.cs
- ClientConfigurationHost.cs
- UnauthorizedWebPart.cs
- SqlSelectStatement.cs
- QuotedStringFormatReader.cs
- HwndAppCommandInputProvider.cs
- Enumerable.cs
- SponsorHelper.cs
- WorkflowMarkupElementEventArgs.cs
- ResizingMessageFilter.cs
- CodeConditionStatement.cs
- PipeStream.cs
- ContractUtils.cs
- FlowLayoutPanelDesigner.cs
- UInt16.cs
- MailMessage.cs
- MouseActionValueSerializer.cs
- HttpApplicationFactory.cs
- SystemResourceHost.cs
- BoundsDrawingContextWalker.cs
- Margins.cs
- HttpBrowserCapabilitiesBase.cs
- XmlSchemaExternal.cs
- arabicshape.cs
- PropertyCollection.cs
- SafeProcessHandle.cs
- CommonDialog.cs
- CodeLinePragma.cs
- DrawingAttributes.cs
- HtmlControlPersistable.cs
- SafePointer.cs
- ObjectSecurityT.cs
- ListQueryResults.cs
- StreamAsIStream.cs
- LineServicesRun.cs
- Utilities.cs
- SerializableTypeCodeDomSerializer.cs
- PKCS1MaskGenerationMethod.cs
- ApplicationBuildProvider.cs
- ClientTargetCollection.cs
- OrderedHashRepartitionStream.cs
- ListBindableAttribute.cs
- QilReplaceVisitor.cs
- MemberInfoSerializationHolder.cs
- PointLightBase.cs
- TextModifier.cs
- CodeArgumentReferenceExpression.cs
- TableLayout.cs
- InstanceLockQueryResult.cs
- Zone.cs
- EventMemberCodeDomSerializer.cs
- Error.cs
- LinkTarget.cs
- SafeSystemMetrics.cs
- ActivityInterfaces.cs
- QuestionEventArgs.cs
- DataGridViewHeaderCell.cs
- JsonReaderDelegator.cs
- HttpClientCertificate.cs
- UnsafeNativeMethodsMilCoreApi.cs
- ObjectCloneHelper.cs
- Enum.cs
- ChannelEndpointElement.cs
- DynamicPropertyHolder.cs
- CalculatedColumn.cs
- NavigationPropertyEmitter.cs
- ToolStripItemEventArgs.cs
- DrawTreeNodeEventArgs.cs
- MetaColumn.cs
- TemplateField.cs
- ScaleTransform3D.cs
- TimeSpan.cs
- HtmlWindow.cs