Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / 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. /****************************************************************************\ * * 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
- ActiveXSite.cs
- SqlNamer.cs
- DataGridViewRowCollection.cs
- UnmanagedMemoryStreamWrapper.cs
- XmlAttributeCache.cs
- SiteMapPathDesigner.cs
- cookiecontainer.cs
- RequestDescription.cs
- SigningCredentials.cs
- MissingSatelliteAssemblyException.cs
- DataGridViewCellStateChangedEventArgs.cs
- CrossContextChannel.cs
- IIS7UserPrincipal.cs
- TrackingServices.cs
- CustomValidator.cs
- MediaCommands.cs
- ExpressionEditorSheet.cs
- WriteFileContext.cs
- CodeTypeParameter.cs
- RegularExpressionValidator.cs
- MarginCollapsingState.cs
- FullTextLine.cs
- ToolStripGrip.cs
- NetPeerTcpBinding.cs
- FormatterServices.cs
- WebPageTraceListener.cs
- CheckBoxFlatAdapter.cs
- Closure.cs
- SystemIcmpV6Statistics.cs
- TableCell.cs
- HttpStreams.cs
- COM2ExtendedTypeConverter.cs
- ActivationArguments.cs
- Statements.cs
- ViewCellSlot.cs
- JulianCalendar.cs
- OdbcErrorCollection.cs
- ConfigurationValue.cs
- MiniParameterInfo.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- UnsafeNativeMethods.cs
- ConcurrentStack.cs
- DataGridPagingPage.cs
- PrePostDescendentsWalker.cs
- XslException.cs
- pingexception.cs
- ImageCollectionCodeDomSerializer.cs
- CodeDOMUtility.cs
- StateManagedCollection.cs
- OleDragDropHandler.cs
- LogLogRecord.cs
- WebRequestModulesSection.cs
- CompensationParticipant.cs
- SqlDataReaderSmi.cs
- Stream.cs
- SqlClientFactory.cs
- InnerItemCollectionView.cs
- DataTableMappingCollection.cs
- BuiltInExpr.cs
- ScriptingAuthenticationServiceSection.cs
- WebBrowserEvent.cs
- NonNullItemCollection.cs
- Hyperlink.cs
- XmlSchemaCompilationSettings.cs
- RC2.cs
- XamlRtfConverter.cs
- OpenTypeLayout.cs
- SymbolType.cs
- xamlnodes.cs
- SqlGenerator.cs
- SmiGettersStream.cs
- Unit.cs
- NavigationPropertyEmitter.cs
- ZipIOExtraFieldElement.cs
- WebPartChrome.cs
- ProfileProvider.cs
- CheckBoxField.cs
- _Rfc2616CacheValidators.cs
- RepeaterDesigner.cs
- HwndSource.cs
- GenericUriParser.cs
- AstTree.cs
- prompt.cs
- FamilyMap.cs
- LocalizableResourceBuilder.cs
- RenderOptions.cs
- MailWriter.cs
- RuntimeIdentifierPropertyAttribute.cs
- Timeline.cs
- HandlerBase.cs
- SortKey.cs
- BamlBinaryWriter.cs
- InvokePattern.cs
- SessionEndingCancelEventArgs.cs
- EntitySqlException.cs
- CFGGrammar.cs
- XmlWriterSettings.cs
- Partitioner.cs
- nulltextcontainer.cs
- WindowsComboBox.cs