Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / System / Windows / Markup / DependencyPropertyConverter.cs / 1 / DependencyPropertyConverter.cs
/****************************************************************************\ * * File: DependencyPropertyConverter.cs * * Class for converting a given DependencyProperty to and from a string * * Copyright (C) 2005 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.ComponentModel; // for TypeConverter using System.Globalization; // for CultureInfo using System.Reflection; using MS.Utility; using MS.Internal; using System.Windows; using System.ComponentModel.Design.Serialization; using System.Windows.Documents; namespace System.Windows.Markup { ////// Class for converting a given DependencyProperty to and from a string /// public sealed class DependencyPropertyConverter : TypeConverter { #region Public Methods ////// CanConvertFrom() /// /// ITypeDescriptorContext /// type to convert from ///true if the given type can be converted, flase otherwise public override bool CanConvertFrom(ITypeDescriptorContext context, 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) && (context is TypeConvertContext)) { return true; } return false; } ////// TypeConverter method override. /// /// ITypeDescriptorContext /// Type to convert to ///true if conversion is possible public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return false; } ////// ConvertFrom() -TypeConverter method override. using the givein name to return DependencyProperty /// /// ITypeDescriptorContext /// CultureInfo /// Object to convert from ///instance of Command public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source) { TypeConvertContext typeConvertContext = context as TypeConvertContext; if (source is string && typeConvertContext != null) { ParserContext parserContext = typeConvertContext.ParserContext; // Find the ownerType from the parser context (this should be generalized, but for now // hard-coded to style & template) Type ownerType = null; ownerType = parserContext.TargetType; DependencyProperty dp = XamlTypeMapper.ParsePropertyName(parserContext, ((string)source).Trim(), ref ownerType); return dp; } throw GetConvertFromException(source); } ////// ConvertTo() - Serialization purposes, returns the string from Command.Name by adding ownerType.FullName /// /// ITypeDescriptorContext /// CultureInfo /// the object to convert from /// the type to convert to ///string object, if the destination type is string public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { throw GetConvertToException(value, destinationType); } #endregion Public Methods } } // 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
- StatusBarItemAutomationPeer.cs
- ExpandCollapseProviderWrapper.cs
- LinkLabel.cs
- EditorZoneBase.cs
- EllipticalNodeOperations.cs
- AutomationPeer.cs
- DocumentGridPage.cs
- SafeEventLogWriteHandle.cs
- WebServiceReceiveDesigner.cs
- SymbolTable.cs
- BooleanToVisibilityConverter.cs
- CodePageUtils.cs
- DataSourceProvider.cs
- DataSet.cs
- AbsoluteQuery.cs
- CodeDomConfigurationHandler.cs
- UrlMapping.cs
- EdmValidator.cs
- BamlLocalizableResourceKey.cs
- FastPropertyAccessor.cs
- GridLengthConverter.cs
- XmlImplementation.cs
- WsatRegistrationHeader.cs
- OutputChannelBinder.cs
- UnionCqlBlock.cs
- CompositeFontFamily.cs
- Int32.cs
- DataFieldEditor.cs
- ValidationResults.cs
- PartManifestEntry.cs
- BCLDebug.cs
- DbgUtil.cs
- PropertyBuilder.cs
- SettingsPropertyValueCollection.cs
- SettingsAttributes.cs
- MoveSizeWinEventHandler.cs
- WebPartDescription.cs
- RenderDataDrawingContext.cs
- HttpStreamXmlDictionaryReader.cs
- MemoryRecordBuffer.cs
- UpdateRecord.cs
- ReferenceConverter.cs
- RequestCache.cs
- XmlToDatasetMap.cs
- RoleManagerSection.cs
- EncryptedPackageFilter.cs
- UIInitializationException.cs
- WebServicesSection.cs
- CommaDelimitedStringAttributeCollectionConverter.cs
- InitializationEventAttribute.cs
- HttpInputStream.cs
- KeySpline.cs
- TemplatePropertyEntry.cs
- DependencyPropertyChangedEventArgs.cs
- ReadonlyMessageFilter.cs
- Visual3DCollection.cs
- PageAsyncTaskManager.cs
- CodeTypeParameter.cs
- TextViewSelectionProcessor.cs
- RIPEMD160.cs
- RegexGroupCollection.cs
- MarginsConverter.cs
- CLRBindingWorker.cs
- CompositeDataBoundControl.cs
- TypeSystem.cs
- BCryptNative.cs
- PerspectiveCamera.cs
- PropertyTabChangedEvent.cs
- StylusOverProperty.cs
- CodeIdentifier.cs
- PropertyGridEditorPart.cs
- ActivityDelegate.cs
- GlobalItem.cs
- AnnotationStore.cs
- SerializationFieldInfo.cs
- DataServiceRequestException.cs
- HtmlShimManager.cs
- ContentPlaceHolder.cs
- EntityCommand.cs
- Compiler.cs
- XmlElementAttributes.cs
- EntityModelSchemaGenerator.cs
- DataRowView.cs
- TryExpression.cs
- ServiceBehaviorAttribute.cs
- CodeTypeMemberCollection.cs
- ParenthesizePropertyNameAttribute.cs
- DataControlPagerLinkButton.cs
- TextParaClient.cs
- _OverlappedAsyncResult.cs
- CompiledXpathExpr.cs
- GeometryHitTestParameters.cs
- MatrixAnimationUsingKeyFrames.cs
- ListItemConverter.cs
- RegexMatchCollection.cs
- TableAutomationPeer.cs
- UdpDiscoveryEndpointProvider.cs
- BCLDebug.cs
- QueryCursorEventArgs.cs
- EntityContainerEmitter.cs