Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Markup / RoutedEventConverter.cs / 1 / RoutedEventConverter.cs
// Copyright (C) Microsoft Corporation. All rights reserved. using System.ComponentModel; using System.Globalization; using System.Windows; namespace System.Windows.Markup { ////// Type converter for RoutedEvent type /// public sealed class RoutedEventConverter: 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) && (typeDescriptorContext is TypeConvertContext)) { 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) { string routedEventName = source as string; if( routedEventName != null ) { IServiceProvider serviceProvier = typeDescriptorContext as IServiceProvider; if (serviceProvier != null) { TypeConvertContext typeConvertContext = typeDescriptorContext as TypeConvertContext; ParserContext parserContext = typeConvertContext == null ? null : typeConvertContext.ParserContext; if( parserContext != null ) { XamlTypeMapper xamlTypeMapper = parserContext.XamlTypeMapper; if( xamlTypeMapper != null ) { RoutedEvent routedEvent; string nameSpace; nameSpace = ExtractNamespaceString( ref routedEventName, parserContext ); // Verify that there's at least one period. (A simple // but not foolproof check for "[class].[event]") if( routedEventName.IndexOf('.') != -1 ) { // When xamlTypeMapper is told to look for RoutedEventID, // we need "[class].[event]" because at this point we // have no idea what the owner type might be. // Fortunately, given "[class].[event]" xamlTypeMapper.GetRoutedEventID // can figure things out, so at this point we can pass // in 'null' for the ownerType and things will still work. routedEvent = xamlTypeMapper.GetRoutedEvent(null /* ownerType */, nameSpace, routedEventName); return routedEvent; } } } } } // Falling through here means we are unable to perform the conversion. 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); } // This routine is copied from TemplateBamlRecordReader. This functionality // is planned to be part of the utilities exposed by the parser, eliminating // the need to duplicate code. See task #18279 private string ExtractNamespaceString( ref string nameString, ParserContext parserContext ) { // The colon is what we look for to determine if there's a namespace prefix specifier. int nsIndex = nameString.IndexOf(':'); string nsPrefix = string.Empty; if( nsIndex != -1 ) { // Found a namespace prefix separator, so create replacement propertyName. // String processing - split "foons" from "BarClass.BazProp" nsPrefix = nameString.Substring (0, nsIndex); nameString = nameString.Substring (nsIndex + 1); } // Find the namespace, even if its the default one string namespaceURI = parserContext.XmlnsDictionary[nsPrefix]; if (namespaceURI == null) { throw new ArgumentException(SR.Get(SRID.ParserPrefixNSProperty, nsPrefix, nameString)); } return namespaceURI; } } } // 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; namespace System.Windows.Markup { ////// Type converter for RoutedEvent type /// public sealed class RoutedEventConverter: 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) && (typeDescriptorContext is TypeConvertContext)) { 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) { string routedEventName = source as string; if( routedEventName != null ) { IServiceProvider serviceProvier = typeDescriptorContext as IServiceProvider; if (serviceProvier != null) { TypeConvertContext typeConvertContext = typeDescriptorContext as TypeConvertContext; ParserContext parserContext = typeConvertContext == null ? null : typeConvertContext.ParserContext; if( parserContext != null ) { XamlTypeMapper xamlTypeMapper = parserContext.XamlTypeMapper; if( xamlTypeMapper != null ) { RoutedEvent routedEvent; string nameSpace; nameSpace = ExtractNamespaceString( ref routedEventName, parserContext ); // Verify that there's at least one period. (A simple // but not foolproof check for "[class].[event]") if( routedEventName.IndexOf('.') != -1 ) { // When xamlTypeMapper is told to look for RoutedEventID, // we need "[class].[event]" because at this point we // have no idea what the owner type might be. // Fortunately, given "[class].[event]" xamlTypeMapper.GetRoutedEventID // can figure things out, so at this point we can pass // in 'null' for the ownerType and things will still work. routedEvent = xamlTypeMapper.GetRoutedEvent(null /* ownerType */, nameSpace, routedEventName); return routedEvent; } } } } } // Falling through here means we are unable to perform the conversion. 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); } // This routine is copied from TemplateBamlRecordReader. This functionality // is planned to be part of the utilities exposed by the parser, eliminating // the need to duplicate code. See task #18279 private string ExtractNamespaceString( ref string nameString, ParserContext parserContext ) { // The colon is what we look for to determine if there's a namespace prefix specifier. int nsIndex = nameString.IndexOf(':'); string nsPrefix = string.Empty; if( nsIndex != -1 ) { // Found a namespace prefix separator, so create replacement propertyName. // String processing - split "foons" from "BarClass.BazProp" nsPrefix = nameString.Substring (0, nsIndex); nameString = nameString.Substring (nsIndex + 1); } // Find the namespace, even if its the default one string namespaceURI = parserContext.XmlnsDictionary[nsPrefix]; if (namespaceURI == null) { throw new ArgumentException(SR.Get(SRID.ParserPrefixNSProperty, nsPrefix, nameString)); } return namespaceURI; } } } // 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
- ToolStripMenuItemDesigner.cs
- ControlCollection.cs
- SerializableAttribute.cs
- SqlRetyper.cs
- ResetableIterator.cs
- OracleCommand.cs
- DesignerUtility.cs
- MimeReflector.cs
- CalculatedColumn.cs
- BufferAllocator.cs
- TabletDeviceInfo.cs
- JpegBitmapEncoder.cs
- StateManager.cs
- Attribute.cs
- ColorConvertedBitmapExtension.cs
- AttributeEmitter.cs
- TrustManagerPromptUI.cs
- DateTimeConverter2.cs
- WebPartEditVerb.cs
- FacetValues.cs
- ListViewInsertEventArgs.cs
- InvalidComObjectException.cs
- BlockUIContainer.cs
- DataGridViewButtonCell.cs
- MenuItemStyle.cs
- ResolveNameEventArgs.cs
- NumberEdit.cs
- ModelVisual3D.cs
- BidPrivateBase.cs
- DataSetMappper.cs
- Stylus.cs
- RepeatBehaviorConverter.cs
- BindableTemplateBuilder.cs
- OlePropertyStructs.cs
- ActiveXHelper.cs
- LassoSelectionBehavior.cs
- HttpModulesSection.cs
- Facet.cs
- HttpListenerRequest.cs
- PathFigureCollection.cs
- PersonalizationEntry.cs
- Parser.cs
- ReflectTypeDescriptionProvider.cs
- ReaderWriterLockWrapper.cs
- DesignerCommandSet.cs
- CodeComment.cs
- HwndHost.cs
- RadioButtonList.cs
- KeyFrames.cs
- SecurityIdentifierConverter.cs
- EditorOptionAttribute.cs
- CodeRegionDirective.cs
- NameHandler.cs
- WindowsScrollBarBits.cs
- ThaiBuddhistCalendar.cs
- SecurityRuntime.cs
- DataGridViewImageColumn.cs
- ScrollItemProviderWrapper.cs
- DataGridPagingPage.cs
- SiteMapDataSource.cs
- TimersDescriptionAttribute.cs
- Tokenizer.cs
- ExtensionMethods.cs
- EntityWithChangeTrackerStrategy.cs
- AdRotator.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- FtpWebRequest.cs
- CompatibleComparer.cs
- View.cs
- Token.cs
- UniqueEventHelper.cs
- ObjectHelper.cs
- DbCommandDefinition.cs
- ToolStripItemRenderEventArgs.cs
- _TransmitFileOverlappedAsyncResult.cs
- BCryptSafeHandles.cs
- AxisAngleRotation3D.cs
- QueryTask.cs
- peersecurityelement.cs
- ExtendedProtectionPolicyTypeConverter.cs
- hebrewshape.cs
- AnnotationHelper.cs
- AuthorizationRuleCollection.cs
- AnalyzedTree.cs
- ArgumentNullException.cs
- FormsAuthenticationUserCollection.cs
- WebPartCatalogCloseVerb.cs
- WindowsMenu.cs
- ListViewItemMouseHoverEvent.cs
- Utils.cs
- EventLogPermissionEntry.cs
- ArgumentOutOfRangeException.cs
- MarkupExtensionReturnTypeAttribute.cs
- HelpInfo.cs
- ParseNumbers.cs
- AsyncOperationManager.cs
- DictionaryChange.cs
- SaveFileDialog.cs
- ViewgenContext.cs
- FillBehavior.cs