Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- FindCriteriaApril2005.cs
- Line.cs
- GridViewCommandEventArgs.cs
- Page.cs
- FontUnitConverter.cs
- VisualStyleRenderer.cs
- DocumentSequenceHighlightLayer.cs
- ObfuscateAssemblyAttribute.cs
- DesignerSerializerAttribute.cs
- LogicalTreeHelper.cs
- SelectorItemAutomationPeer.cs
- XmlWrappingWriter.cs
- SelectionProcessor.cs
- DesignSurfaceServiceContainer.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- pingexception.cs
- _TLSstream.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- Package.cs
- NamedObject.cs
- Page.cs
- ExecutedRoutedEventArgs.cs
- SemanticBasicElement.cs
- TagNameToTypeMapper.cs
- SinglePageViewer.cs
- CompositeScriptReference.cs
- AppSecurityManager.cs
- WebPartMenuStyle.cs
- ParseHttpDate.cs
- QilXmlWriter.cs
- DesignerLinkAdapter.cs
- Mouse.cs
- Tool.cs
- WinCategoryAttribute.cs
- QilValidationVisitor.cs
- MethodBuilderInstantiation.cs
- HorizontalAlignConverter.cs
- PackageProperties.cs
- MenuScrollingVisibilityConverter.cs
- GeometryCombineModeValidation.cs
- TextServicesDisplayAttributePropertyRanges.cs
- MetadataItemEmitter.cs
- RowUpdatingEventArgs.cs
- ByteAnimation.cs
- MsdtcWrapper.cs
- SafeNativeMethodsMilCoreApi.cs
- DynamicAttribute.cs
- ZipIOExtraFieldZip64Element.cs
- ISAPIRuntime.cs
- InternalReceiveMessage.cs
- C14NUtil.cs
- UrlMappingsSection.cs
- BaseInfoTable.cs
- XsdBuildProvider.cs
- SymDocumentType.cs
- MembershipPasswordException.cs
- UnionExpr.cs
- MenuScrollingVisibilityConverter.cs
- TypeUtils.cs
- HighlightVisual.cs
- FileNotFoundException.cs
- CounterSample.cs
- EventLogLink.cs
- AttachedPropertyBrowsableAttribute.cs
- SqlParameterCollection.cs
- XPathSelfQuery.cs
- WorkflowIdleElement.cs
- IntegerValidator.cs
- RectAnimationBase.cs
- ProcessingInstructionAction.cs
- SizeValueSerializer.cs
- RectAnimationClockResource.cs
- StateRuntime.cs
- StreamGeometry.cs
- ButtonBaseAdapter.cs
- FileReader.cs
- SqlUDTStorage.cs
- DurableInstanceContextProvider.cs
- ClassDataContract.cs
- TextEditorMouse.cs
- securitycriticaldata.cs
- CapabilitiesPattern.cs
- ACL.cs
- AttributeCollection.cs
- Model3D.cs
- SettingsPropertyNotFoundException.cs
- ConcurrentQueue.cs
- DynamicPropertyHolder.cs
- TextDocumentView.cs
- Html32TextWriter.cs
- ValidatorUtils.cs
- UserControl.cs
- BuildProvider.cs
- _SecureChannel.cs
- CommandEventArgs.cs
- LabelExpression.cs
- ToolStripRenderEventArgs.cs
- OrderingInfo.cs
- WinEventTracker.cs
- TextFormatter.cs