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 / Condition.cs / 1 / Condition.cs
using MS.Utility; using System.IO; using System.Windows.Markup; using System.ComponentModel; using System; using System.Windows.Data; namespace System.Windows { ////// Condition for a multiple property or data trigger /// public sealed class Condition { ////// Constructor with no property reference nor value /// public Condition() { _property = null; _binding = null; } ////// Constructor for creating a Condition /// public Condition( DependencyProperty conditionProperty, object conditionValue ) : this(conditionProperty, conditionValue, null) { // Call Forwarded } ////// Constructor for creating a Condition with the given property /// and value instead of creating an empty one and setting values later. /// ////// This constructor does parameter validation, which before doesn't /// happen until Seal() is called. We can do it here because we get /// both at the same time. /// public Condition( DependencyProperty conditionProperty, object conditionValue, string sourceName ) { if( conditionProperty == null ) { throw new ArgumentNullException("conditionProperty"); } if( !conditionProperty.IsValidValue( conditionValue ) ) { throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, conditionValue, conditionProperty.Name)); } _property = conditionProperty; Value = conditionValue; _sourceName = sourceName; } ////// Constructor for creating a Condition with the given binding declaration. /// and value. /// public Condition( BindingBase binding, object conditionValue ) { if( binding == null ) { throw new ArgumentNullException("binding"); } Binding = binding; Value = conditionValue; } ////// DepedencyProperty of the conditional /// [Ambient] [DefaultValue(null)] public DependencyProperty Property { get { return _property; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if( _binding != null ) { throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); } _property = value; } } ////// Binding of the conditional /// [DefaultValue(null)] public BindingBase Binding { get { return _binding; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if( _property != null ) { throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); } _binding = value; } } ////// Value of the condition (equality check) /// public object Value { get { return _value; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if (value is MarkupExtension) { throw new ArgumentException(SR.Get(SRID.ConditionValueOfMarkupExtensionNotSupported, value.GetType().Name)); } if( value is Expression ) { throw new ArgumentException(SR.Get(SRID.ConditionValueOfExpressionNotSupported)); } _value = value; } } ////// The x:Name of the object whose property shall /// trigger the associated setters to be applied. /// If null, then this is the object being Styled /// and not anything under its Template Tree. /// [DefaultValue(null)] public string SourceName { get { return _sourceName; } set { if( _sealed ) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } _sourceName = value; } } ////// Seal the condition so that it can no longer be modified /// internal void Seal(ValueLookupType type) { if (_sealed) { return; } _sealed = true; // Ensure valid condition if (_property != null && _binding != null) throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); switch (type) { case ValueLookupType.Trigger: case ValueLookupType.PropertyTriggerResource: if (_property == null) { throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Property")); } if (!_property.IsValidValue(_value)) { throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, _value, _property.Name)); } break; case ValueLookupType.DataTrigger: case ValueLookupType.DataTriggerResource: if (_binding == null) { throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Binding")); } break; default: throw new InvalidOperationException(SR.Get(SRID.UnexpectedValueTypeForCondition, type)); } // Freeze the condition value StyleHelper.SealIfSealable(_value); } private bool _sealed = false; private DependencyProperty _property; private BindingBase _binding; private object _value = DependencyProperty.UnsetValue; private string _sourceName = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using MS.Utility; using System.IO; using System.Windows.Markup; using System.ComponentModel; using System; using System.Windows.Data; namespace System.Windows { ////// Condition for a multiple property or data trigger /// public sealed class Condition { ////// Constructor with no property reference nor value /// public Condition() { _property = null; _binding = null; } ////// Constructor for creating a Condition /// public Condition( DependencyProperty conditionProperty, object conditionValue ) : this(conditionProperty, conditionValue, null) { // Call Forwarded } ////// Constructor for creating a Condition with the given property /// and value instead of creating an empty one and setting values later. /// ////// This constructor does parameter validation, which before doesn't /// happen until Seal() is called. We can do it here because we get /// both at the same time. /// public Condition( DependencyProperty conditionProperty, object conditionValue, string sourceName ) { if( conditionProperty == null ) { throw new ArgumentNullException("conditionProperty"); } if( !conditionProperty.IsValidValue( conditionValue ) ) { throw new ArgumentException(SR.Get(SRID.InvalidPropertyValue, conditionValue, conditionProperty.Name)); } _property = conditionProperty; Value = conditionValue; _sourceName = sourceName; } ////// Constructor for creating a Condition with the given binding declaration. /// and value. /// public Condition( BindingBase binding, object conditionValue ) { if( binding == null ) { throw new ArgumentNullException("binding"); } Binding = binding; Value = conditionValue; } ////// DepedencyProperty of the conditional /// [Ambient] [DefaultValue(null)] public DependencyProperty Property { get { return _property; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if( _binding != null ) { throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); } _property = value; } } ////// Binding of the conditional /// [DefaultValue(null)] public BindingBase Binding { get { return _binding; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if( _property != null ) { throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); } _binding = value; } } ////// Value of the condition (equality check) /// public object Value { get { return _value; } set { if (_sealed) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } if (value is MarkupExtension) { throw new ArgumentException(SR.Get(SRID.ConditionValueOfMarkupExtensionNotSupported, value.GetType().Name)); } if( value is Expression ) { throw new ArgumentException(SR.Get(SRID.ConditionValueOfExpressionNotSupported)); } _value = value; } } ////// The x:Name of the object whose property shall /// trigger the associated setters to be applied. /// If null, then this is the object being Styled /// and not anything under its Template Tree. /// [DefaultValue(null)] public string SourceName { get { return _sourceName; } set { if( _sealed ) { throw new InvalidOperationException(SR.Get(SRID.CannotChangeAfterSealed, "Condition")); } _sourceName = value; } } ////// Seal the condition so that it can no longer be modified /// internal void Seal(ValueLookupType type) { if (_sealed) { return; } _sealed = true; // Ensure valid condition if (_property != null && _binding != null) throw new InvalidOperationException(SR.Get(SRID.ConditionCannotUseBothPropertyAndBinding)); switch (type) { case ValueLookupType.Trigger: case ValueLookupType.PropertyTriggerResource: if (_property == null) { throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Property")); } if (!_property.IsValidValue(_value)) { throw new InvalidOperationException(SR.Get(SRID.InvalidPropertyValue, _value, _property.Name)); } break; case ValueLookupType.DataTrigger: case ValueLookupType.DataTriggerResource: if (_binding == null) { throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "Binding")); } break; default: throw new InvalidOperationException(SR.Get(SRID.UnexpectedValueTypeForCondition, type)); } // Freeze the condition value StyleHelper.SealIfSealable(_value); } private bool _sealed = false; private DependencyProperty _property; private BindingBase _binding; private object _value = DependencyProperty.UnsetValue; private string _sourceName = 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
- NegotiateStream.cs
- DbDataSourceEnumerator.cs
- VideoDrawing.cs
- GeneralTransform3DGroup.cs
- ConversionHelper.cs
- OutputCache.cs
- XmlSchemaException.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- WebScriptMetadataMessageEncoderFactory.cs
- MimeObjectFactory.cs
- FileEnumerator.cs
- EntitySqlQueryBuilder.cs
- DataKeyCollection.cs
- HelpInfo.cs
- WebPartUserCapability.cs
- ConversionHelper.cs
- QilReplaceVisitor.cs
- TextSelectionHighlightLayer.cs
- OutputCacheSettingsSection.cs
- DefaultPropertyAttribute.cs
- DesignerAdapterUtil.cs
- VirtualDirectoryMapping.cs
- DivideByZeroException.cs
- WinEventTracker.cs
- PseudoWebRequest.cs
- ViewManager.cs
- VirtualPathUtility.cs
- DocumentGridContextMenu.cs
- ActivationServices.cs
- FreeFormDragDropManager.cs
- ServiceNameCollection.cs
- EditorPart.cs
- QilInvoke.cs
- TableSectionStyle.cs
- WebServicesDescriptionAttribute.cs
- ClientData.cs
- FileClassifier.cs
- SharedPersonalizationStateInfo.cs
- AssemblyFilter.cs
- PopupRootAutomationPeer.cs
- XmlSchemaAppInfo.cs
- LocalizableAttribute.cs
- CollectionViewGroup.cs
- KeyedCollection.cs
- InsufficientMemoryException.cs
- OdbcHandle.cs
- Stacktrace.cs
- WSFederationHttpBinding.cs
- ExtendedPropertyCollection.cs
- CallbackHandler.cs
- AppDomainResourcePerfCounters.cs
- ContextDataSourceView.cs
- embossbitmapeffect.cs
- FactoryId.cs
- EUCJPEncoding.cs
- VScrollProperties.cs
- ShapingWorkspace.cs
- DataSourceCache.cs
- HttpConfigurationSystem.cs
- CompilationRelaxations.cs
- ArraySortHelper.cs
- DesignerSerializationVisibilityAttribute.cs
- RowType.cs
- ReflectEventDescriptor.cs
- LineProperties.cs
- LockedBorderGlyph.cs
- AnimatedTypeHelpers.cs
- WebRequestModulesSection.cs
- ThreadAttributes.cs
- ApplicationServiceHelper.cs
- FilterQuery.cs
- CustomTypeDescriptor.cs
- ArraySet.cs
- FileDialogCustomPlace.cs
- SystemColorTracker.cs
- SyntaxCheck.cs
- ProfileEventArgs.cs
- ByteStreamMessageEncoder.cs
- NotifyIcon.cs
- HwndSubclass.cs
- RawStylusSystemGestureInputReport.cs
- ProcessManager.cs
- DeviceContext.cs
- CompositeActivityValidator.cs
- SettingsAttributes.cs
- Message.cs
- HuffmanTree.cs
- SecurityTokenProviderContainer.cs
- XmlReaderSettings.cs
- HeaderUtility.cs
- BaseTemplateParser.cs
- TCEAdapterGenerator.cs
- WinInetCache.cs
- DataObjectPastingEventArgs.cs
- PcmConverter.cs
- BitmapEffectRenderDataResource.cs
- ToolboxComponentsCreatingEventArgs.cs
- WindowsSolidBrush.cs
- BitmapFrame.cs
- XmlHierarchicalEnumerable.cs