Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / MS / Internal / Ink / StrokeCollectionDefaultValueFactory.cs / 1 / StrokeCollectionDefaultValueFactory.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DefaultValueFactory for StrokeCollection // // History: // 2006/01/24 : waynezen - Created // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; namespace MS.Internal.Ink { internal class StrokeCollectionDefaultValueFactory : DefaultValueFactory { internal StrokeCollectionDefaultValueFactory() { } ////// Returns an "immutable" default value. Since we can't make the default value /// read only we'll return a new one every time. /// internal override object DefaultValue { get { return new StrokeCollection(); } } ////// Creates a mutable default value /// internal override object CreateDefaultValue(DependencyObject owner, DependencyProperty property) { Debug.Assert(property.PropertyType == typeof(StrokeCollection), string.Format(System.Globalization.CultureInfo.InvariantCulture, "The DependencyProperty {0} has to be type of StrokeCollection.", property)); // Instantiate our default value instance. StrokeCollection defaultValue = new StrokeCollection(); // Add event handlers for tracking the changes on the default value instance. StrokeCollectionDefaultPromoter promoter = new StrokeCollectionDefaultPromoter(owner, property); defaultValue.StrokesChanged += new StrokeCollectionChangedEventHandler(promoter.OnStrokeCollectionChanged); defaultValue.PropertyDataChanged += new PropertyDataChangedEventHandler(promoter.OnStrokeCollectionChanged ); return defaultValue; } /// /// A tracking class which monitors any changes on StrokeCollection /// private class StrokeCollectionDefaultPromoter { ////// Constructor /// /// /// internal StrokeCollectionDefaultPromoter(DependencyObject owner, DependencyProperty property) { _owner = owner; _dependencyProperty = property; } ////// A handler for both AttributeChanged and PropertyDataChanged. /// /// /// internal void OnStrokeCollectionChanged(object sender, TEventArgs e) { StrokeCollection value = (StrokeCollection)sender; // The current instance will be promoted to the local value other than the default value. // Then we could just remove our handlers to stop tracking. value.StrokesChanged -= new StrokeCollectionChangedEventHandler(OnStrokeCollectionChanged ); value.PropertyDataChanged -= new PropertyDataChangedEventHandler(OnStrokeCollectionChanged ); // NTRAID#WINDOWS-1334059-2005/10/17-waynezen, // We only promote the value when there is no local value set yet. if ( _owner.ReadLocalValue(_dependencyProperty) == DependencyProperty.UnsetValue ) { // Promote the instance to the local value. _owner.SetValue(_dependencyProperty, value); } // Remove this value from the DefaultValue cache so we stop // handing it out as the default value now that it has changed. PropertyMetadata metadata = _dependencyProperty.GetMetadata(_owner.DependencyObjectType); metadata.ClearCachedDefaultValue(_owner, _dependencyProperty); } private readonly DependencyObject _owner; private readonly DependencyProperty _dependencyProperty; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // // Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DefaultValueFactory for StrokeCollection // // History: // 2006/01/24 : waynezen - Created // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; namespace MS.Internal.Ink { internal class StrokeCollectionDefaultValueFactory : DefaultValueFactory { internal StrokeCollectionDefaultValueFactory() { } ////// Returns an "immutable" default value. Since we can't make the default value /// read only we'll return a new one every time. /// internal override object DefaultValue { get { return new StrokeCollection(); } } ////// Creates a mutable default value /// internal override object CreateDefaultValue(DependencyObject owner, DependencyProperty property) { Debug.Assert(property.PropertyType == typeof(StrokeCollection), string.Format(System.Globalization.CultureInfo.InvariantCulture, "The DependencyProperty {0} has to be type of StrokeCollection.", property)); // Instantiate our default value instance. StrokeCollection defaultValue = new StrokeCollection(); // Add event handlers for tracking the changes on the default value instance. StrokeCollectionDefaultPromoter promoter = new StrokeCollectionDefaultPromoter(owner, property); defaultValue.StrokesChanged += new StrokeCollectionChangedEventHandler(promoter.OnStrokeCollectionChanged); defaultValue.PropertyDataChanged += new PropertyDataChangedEventHandler(promoter.OnStrokeCollectionChanged ); return defaultValue; } /// /// A tracking class which monitors any changes on StrokeCollection /// private class StrokeCollectionDefaultPromoter { ////// Constructor /// /// /// internal StrokeCollectionDefaultPromoter(DependencyObject owner, DependencyProperty property) { _owner = owner; _dependencyProperty = property; } ////// A handler for both AttributeChanged and PropertyDataChanged. /// /// /// internal void OnStrokeCollectionChanged(object sender, TEventArgs e) { StrokeCollection value = (StrokeCollection)sender; // The current instance will be promoted to the local value other than the default value. // Then we could just remove our handlers to stop tracking. value.StrokesChanged -= new StrokeCollectionChangedEventHandler(OnStrokeCollectionChanged ); value.PropertyDataChanged -= new PropertyDataChangedEventHandler(OnStrokeCollectionChanged ); // NTRAID#WINDOWS-1334059-2005/10/17-waynezen, // We only promote the value when there is no local value set yet. if ( _owner.ReadLocalValue(_dependencyProperty) == DependencyProperty.UnsetValue ) { // Promote the instance to the local value. _owner.SetValue(_dependencyProperty, value); } // Remove this value from the DefaultValue cache so we stop // handing it out as the default value now that it has changed. PropertyMetadata metadata = _dependencyProperty.GetMetadata(_owner.DependencyObjectType); metadata.ClearCachedDefaultValue(_owner, _dependencyProperty); } private readonly DependencyObject _owner; private readonly DependencyProperty _dependencyProperty; } } } // 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
- ContentControl.cs
- ValidatorCollection.cs
- ObjectTokenCategory.cs
- SerializationSectionGroup.cs
- ScalarType.cs
- DataGrid.cs
- FileNotFoundException.cs
- DateTimeFormat.cs
- QueryConverter.cs
- SystemWebSectionGroup.cs
- SQLGuid.cs
- DecryptRequest.cs
- AutomationPatternInfo.cs
- CfgParser.cs
- StrongTypingException.cs
- DecimalAnimationBase.cs
- FileAuthorizationModule.cs
- WebReferencesBuildProvider.cs
- MonthCalendarDesigner.cs
- EntityDataSourceConfigureObjectContextPanel.cs
- WebServiceData.cs
- SizeIndependentAnimationStorage.cs
- SuppressMessageAttribute.cs
- RIPEMD160.cs
- SQLInt64.cs
- ReachIDocumentPaginatorSerializer.cs
- WorkflowInspectionServices.cs
- Recipient.cs
- DrawingAttributeSerializer.cs
- PositiveTimeSpanValidator.cs
- DataControlFieldCollection.cs
- InternalTypeHelper.cs
- ProfileProvider.cs
- TdsParserStateObject.cs
- StringFormat.cs
- PenContext.cs
- GlobalizationSection.cs
- InputLanguageCollection.cs
- BorderGapMaskConverter.cs
- CodeCatchClauseCollection.cs
- ScrollChrome.cs
- DBBindings.cs
- TextParagraphCache.cs
- RowUpdatedEventArgs.cs
- MembershipAdapter.cs
- BrowserCapabilitiesFactory.cs
- WmfPlaceableFileHeader.cs
- HtmlEmptyTagControlBuilder.cs
- AccessDataSource.cs
- HttpApplication.cs
- DataPagerCommandEventArgs.cs
- GridItemPatternIdentifiers.cs
- Mapping.cs
- Lasso.cs
- EventItfInfo.cs
- TdsParserSessionPool.cs
- RayMeshGeometry3DHitTestResult.cs
- DockProviderWrapper.cs
- OutputCacheSettingsSection.cs
- ResXFileRef.cs
- XmlSchemaAnnotated.cs
- SafeCoTaskMem.cs
- XPathScanner.cs
- SecurityTokenAttachmentMode.cs
- BulletedListEventArgs.cs
- PageContent.cs
- Pair.cs
- InternalTypeHelper.cs
- FixedDocumentPaginator.cs
- KoreanLunisolarCalendar.cs
- AnnotationObservableCollection.cs
- SelectedGridItemChangedEvent.cs
- ChtmlTextWriter.cs
- WindowsClientElement.cs
- ToolStripContainerActionList.cs
- AssemblyHash.cs
- DataListItem.cs
- CompModSwitches.cs
- UserPreferenceChangingEventArgs.cs
- AspNetSynchronizationContext.cs
- XmlSchemaInfo.cs
- Quad.cs
- ExpressionVisitor.cs
- RenderCapability.cs
- InlineObject.cs
- SecurityDocument.cs
- PartitionerQueryOperator.cs
- ComplexType.cs
- StructuredProperty.cs
- ConfigsHelper.cs
- PhoneCallDesigner.cs
- StorageInfo.cs
- RSACryptoServiceProvider.cs
- SQLSingleStorage.cs
- ConnectionManagementElementCollection.cs
- SoapExtension.cs
- RelationalExpressions.cs
- ObjectQueryExecutionPlan.cs
- MetadataHelper.cs
- OleDbWrapper.cs