Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Setter.cs / 3 / Setter.cs
/****************************************************************************\ * * File: Setter.cs * * TargetType property setting class. * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.ComponentModel; using System.Windows.Markup; #pragma warning disable 1634, 1691 // suppressing PreSharp warnings namespace System.Windows { ////// TargetType property setting class. /// public class Setter : SetterBase { ////// Property Setter construction - set everything to null or DependencyProperty.UnsetValue /// public Setter() { } ////// Property Setter construction - given property and value /// public Setter( DependencyProperty property, object value ) { Initialize( property, value, null ); } ////// Property Setter construction - given property, value, and string identifier for child node. /// public Setter( DependencyProperty property, object value, string targetName ) { Initialize( property, value, targetName ); } ////// Method that does all the initialization work for the constructors. /// private void Initialize( DependencyProperty property, object value, string target ) { if( value == DependencyProperty.UnsetValue ) { throw new ArgumentException(SR.Get(SRID.SetterValueCannotBeUnset)); } CheckValidProperty(property); // No null check for target since null is a valid value. _property = property; _value = value; _target = target; } private void CheckValidProperty( DependencyProperty property) { if (property == null) { throw new ArgumentNullException("property"); } if (property.ReadOnly) { // Read-only properties will not be consulting Style/Template/Trigger Setter for value. // Rather than silently do nothing, throw error. throw new ArgumentException(SR.Get(SRID.ReadOnlyPropertyNotAllowed, property.Name, GetType().Name)); } if( property == FrameworkElement.NameProperty) { throw new InvalidOperationException(SR.Get(SRID.CannotHavePropertyInStyle, FrameworkElement.NameProperty.Name)); } } ////// Seals this setter /// internal override void Seal() { // Do the validation that can't be done until we know all of the property // values. DependencyProperty dp = Property; object value = ValueInternal; if (dp == null) { throw new ArgumentException(SR.Get(SRID.NullPropertyIllegal, "Setter.Property")); } if( String.IsNullOrEmpty(TargetName)) { // Setter on container is not allowed to affect the StyleProperty. if (dp == FrameworkElement.StyleProperty) { throw new ArgumentException(SR.Get(SRID.StylePropertyInStyleNotAllowed)); } } // Value needs to be valid for the DP, or a deferred reference, or one of the supported // markup extensions. if (!dp.IsValidValue(value)) { // The only markup extensions supported by styles is resources and bindings. if (value is MarkupExtension) { if ( !(value is DynamicResourceExtension) && !(value is System.Windows.Data.BindingBase) ) { throw new ArgumentException(SR.Get(SRID.SetterValueOfMarkupExtensionNotSupported, value.GetType().Name)); } } else if (!(value is DeferredReference)) { throw new ArgumentException(SR.Get(SRID.InvalidSetterValue, value, dp.OwnerType, dp.Name)); } } // Styling the logical tree is not supported if (StyleHelper.IsStylingLogicalTree(dp, value)) { throw new NotSupportedException(SR.Get(SRID.ModifyingLogicalTreeViaStylesNotImplemented, value, "Setter.Value")); } // Freeze the value for the setter StyleHelper.SealIfSealable(_value); base.Seal(); } ////// Property that is being set by this setter /// [Ambient] [DefaultValue(null)] [Localizability(LocalizationCategory.None, Modifiability = Modifiability.Unmodifiable, Readability = Readability.Unreadable)] // Not localizable by-default public DependencyProperty Property { get { return _property; } set { CheckValidProperty(value); CheckSealed(); _property = value; } } ////// Property value that is being set by this setter /// [System.Windows.Markup.DependsOn("Property")] [System.Windows.Markup.DependsOn("TargetName")] [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] // Not localizable by-default public object Value { get { // Inflate the deferred reference if the _value is one of those. DeferredReference deferredReference = _value as DeferredReference; if (deferredReference != null) { _value = deferredReference.GetValue(BaseValueSourceInternal.Unknown); } return _value; } set { if( value == DependencyProperty.UnsetValue ) { throw new ArgumentException(SR.Get(SRID.SetterValueCannotBeUnset)); } CheckSealed(); // No Expression support if( value is Expression ) { throw new ArgumentException(SR.Get(SRID.StyleValueOfExpressionNotSupported)); } _value = value; } } ////// Internal property used so that we obtain the value as /// is without having to inflate the DeferredReference. /// internal object ValueInternal { get { return _value; } } ////// When the set is directed at a child node, this string /// identifies the intended target child node. /// [DefaultValue(null)] public string TargetName { get { return _target; } set { // Setting to null is allowed, to clear out value. CheckSealed(); _target = value; } } private DependencyProperty _property = null; private object _value = DependencyProperty.UnsetValue; private string _target = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /****************************************************************************\ * * File: Setter.cs * * TargetType property setting class. * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.ComponentModel; using System.Windows.Markup; #pragma warning disable 1634, 1691 // suppressing PreSharp warnings namespace System.Windows { ////// TargetType property setting class. /// public class Setter : SetterBase { ////// Property Setter construction - set everything to null or DependencyProperty.UnsetValue /// public Setter() { } ////// Property Setter construction - given property and value /// public Setter( DependencyProperty property, object value ) { Initialize( property, value, null ); } ////// Property Setter construction - given property, value, and string identifier for child node. /// public Setter( DependencyProperty property, object value, string targetName ) { Initialize( property, value, targetName ); } ////// Method that does all the initialization work for the constructors. /// private void Initialize( DependencyProperty property, object value, string target ) { if( value == DependencyProperty.UnsetValue ) { throw new ArgumentException(SR.Get(SRID.SetterValueCannotBeUnset)); } CheckValidProperty(property); // No null check for target since null is a valid value. _property = property; _value = value; _target = target; } private void CheckValidProperty( DependencyProperty property) { if (property == null) { throw new ArgumentNullException("property"); } if (property.ReadOnly) { // Read-only properties will not be consulting Style/Template/Trigger Setter for value. // Rather than silently do nothing, throw error. throw new ArgumentException(SR.Get(SRID.ReadOnlyPropertyNotAllowed, property.Name, GetType().Name)); } if( property == FrameworkElement.NameProperty) { throw new InvalidOperationException(SR.Get(SRID.CannotHavePropertyInStyle, FrameworkElement.NameProperty.Name)); } } ////// Seals this setter /// internal override void Seal() { // Do the validation that can't be done until we know all of the property // values. DependencyProperty dp = Property; object value = ValueInternal; if (dp == null) { throw new ArgumentException(SR.Get(SRID.NullPropertyIllegal, "Setter.Property")); } if( String.IsNullOrEmpty(TargetName)) { // Setter on container is not allowed to affect the StyleProperty. if (dp == FrameworkElement.StyleProperty) { throw new ArgumentException(SR.Get(SRID.StylePropertyInStyleNotAllowed)); } } // Value needs to be valid for the DP, or a deferred reference, or one of the supported // markup extensions. if (!dp.IsValidValue(value)) { // The only markup extensions supported by styles is resources and bindings. if (value is MarkupExtension) { if ( !(value is DynamicResourceExtension) && !(value is System.Windows.Data.BindingBase) ) { throw new ArgumentException(SR.Get(SRID.SetterValueOfMarkupExtensionNotSupported, value.GetType().Name)); } } else if (!(value is DeferredReference)) { throw new ArgumentException(SR.Get(SRID.InvalidSetterValue, value, dp.OwnerType, dp.Name)); } } // Styling the logical tree is not supported if (StyleHelper.IsStylingLogicalTree(dp, value)) { throw new NotSupportedException(SR.Get(SRID.ModifyingLogicalTreeViaStylesNotImplemented, value, "Setter.Value")); } // Freeze the value for the setter StyleHelper.SealIfSealable(_value); base.Seal(); } ////// Property that is being set by this setter /// [Ambient] [DefaultValue(null)] [Localizability(LocalizationCategory.None, Modifiability = Modifiability.Unmodifiable, Readability = Readability.Unreadable)] // Not localizable by-default public DependencyProperty Property { get { return _property; } set { CheckValidProperty(value); CheckSealed(); _property = value; } } ////// Property value that is being set by this setter /// [System.Windows.Markup.DependsOn("Property")] [System.Windows.Markup.DependsOn("TargetName")] [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] // Not localizable by-default public object Value { get { // Inflate the deferred reference if the _value is one of those. DeferredReference deferredReference = _value as DeferredReference; if (deferredReference != null) { _value = deferredReference.GetValue(BaseValueSourceInternal.Unknown); } return _value; } set { if( value == DependencyProperty.UnsetValue ) { throw new ArgumentException(SR.Get(SRID.SetterValueCannotBeUnset)); } CheckSealed(); // No Expression support if( value is Expression ) { throw new ArgumentException(SR.Get(SRID.StyleValueOfExpressionNotSupported)); } _value = value; } } ////// Internal property used so that we obtain the value as /// is without having to inflate the DeferredReference. /// internal object ValueInternal { get { return _value; } } ////// When the set is directed at a child node, this string /// identifies the intended target child node. /// [DefaultValue(null)] public string TargetName { get { return _target; } set { // Setting to null is allowed, to clear out value. CheckSealed(); _target = value; } } private DependencyProperty _property = null; private object _value = DependencyProperty.UnsetValue; private string _target = null; } } // 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
- ApplicationManager.cs
- ModelFactory.cs
- AdornedElementPlaceholder.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- StylusSystemGestureEventArgs.cs
- UIElementIsland.cs
- AuthenticateEventArgs.cs
- GrowingArray.cs
- PackageProperties.cs
- ServiceModelExtensionCollectionElement.cs
- StreamGeometry.cs
- LeaseManager.cs
- Sql8ConformanceChecker.cs
- ListViewInsertionMark.cs
- NavigationService.cs
- InternalRelationshipCollection.cs
- TokenFactoryBase.cs
- XmlDocumentFragment.cs
- ReferencedCollectionType.cs
- XmlBindingWorker.cs
- smtpconnection.cs
- TextEffectResolver.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- WindowsContainer.cs
- ValueType.cs
- WebPartVerb.cs
- DetailsViewCommandEventArgs.cs
- DomainUpDown.cs
- DataBindingCollectionConverter.cs
- MultiTrigger.cs
- DataReaderContainer.cs
- BindToObject.cs
- EqualityComparer.cs
- NeedSkipTokenVisitor.cs
- URLIdentityPermission.cs
- XhtmlBasicListAdapter.cs
- EventDescriptorCollection.cs
- NotifyIcon.cs
- ImageInfo.cs
- MetadataAssemblyHelper.cs
- DockProviderWrapper.cs
- WebServiceClientProxyGenerator.cs
- ImageBrush.cs
- ObjectViewListener.cs
- XmlCharCheckingReader.cs
- DataControlPagerLinkButton.cs
- DataGridColumnHeaderAutomationPeer.cs
- ErasingStroke.cs
- WinEventQueueItem.cs
- ImageConverter.cs
- ImageDrawing.cs
- XmlSerializerSection.cs
- Parameter.cs
- altserialization.cs
- securitycriticaldataformultiplegetandset.cs
- DBCommand.cs
- CompositeScriptReference.cs
- TiffBitmapDecoder.cs
- Pen.cs
- TypeTypeConverter.cs
- ETagAttribute.cs
- Point.cs
- SubtreeProcessor.cs
- DiagnosticsConfigurationHandler.cs
- RSACryptoServiceProvider.cs
- ActivityExecutionFilter.cs
- FixedSOMPageConstructor.cs
- PolicyDesigner.cs
- Form.cs
- StructuredTypeEmitter.cs
- MemberInfoSerializationHolder.cs
- FixUp.cs
- ConnectionProviderAttribute.cs
- regiisutil.cs
- BitmapEffectDrawing.cs
- PropertyTabAttribute.cs
- DrawingImage.cs
- ChannelFactory.cs
- MouseActionValueSerializer.cs
- SHA1Managed.cs
- DataService.cs
- coordinator.cs
- SamlAssertionKeyIdentifierClause.cs
- SecurityBindingElement.cs
- GlobalizationAssembly.cs
- TypeReference.cs
- FromRequest.cs
- StateDesigner.TransitionInfo.cs
- SQLConvert.cs
- SecurityPolicySection.cs
- MachineKeyValidationConverter.cs
- Hashtable.cs
- MinimizableAttributeTypeConverter.cs
- ConcurrentDictionary.cs
- RegistryPermission.cs
- DbFunctionCommandTree.cs
- RowsCopiedEventArgs.cs
- TokenBasedSetEnumerator.cs
- DataBoundControl.cs
- PhotoPrintingIntent.cs