Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Ink / DrawingAttributesDefaultValueFactory.cs / 1305600 / DrawingAttributesDefaultValueFactory.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DefaultValueFactory for DrawingAttributes // // History: // 2005/11/08 : [....] - Created // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; namespace MS.Internal.Ink { internal class DrawingAttributesDefaultValueFactory : DefaultValueFactory { internal DrawingAttributesDefaultValueFactory() { } ////// 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 DrawingAttributes(); } } ////// Creates a mutable default value /// internal override object CreateDefaultValue(DependencyObject owner, DependencyProperty property) { // Instantiate our default value instance. DrawingAttributes defaultValue = new DrawingAttributes(); // Add event handlers for tracking the changes on the default value instance. DrawingAttributesDefaultPromoter promoter = new DrawingAttributesDefaultPromoter((InkCanvas)owner); defaultValue.AttributeChanged += new PropertyDataChangedEventHandler(promoter.OnDrawingAttributesChanged); defaultValue.PropertyDataChanged += new PropertyDataChangedEventHandler(promoter.OnDrawingAttributesChanged); return defaultValue; } ////// A tracking class which monitors the sub-property changes on DrawingAttributes /// private class DrawingAttributesDefaultPromoter { ////// Constructor /// /// internal DrawingAttributesDefaultPromoter(InkCanvas owner) { _owner = owner; } ////// A handler for both AttributeChanged and PropertyDataChanged. /// /// /// internal void OnDrawingAttributesChanged(object sender, PropertyDataChangedEventArgs e) { DrawingAttributes value = (DrawingAttributes)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.AttributeChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); value.PropertyDataChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); // NTRAID#WINDOWS-1334059-2005/10/17-waynezen, // We only promote the value when there is no local value set yet. if (_owner.ReadLocalValue(InkCanvas.DefaultDrawingAttributesProperty) == DependencyProperty.UnsetValue) { // Promote the instance to the local value. _owner.SetValue(InkCanvas.DefaultDrawingAttributesProperty, 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 = InkCanvas.DefaultDrawingAttributesProperty.GetMetadata(_owner.DependencyObjectType); metadata.ClearCachedDefaultValue(_owner, InkCanvas.DefaultDrawingAttributesProperty); } private readonly InkCanvas _owner; } } } // 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 DrawingAttributes // // History: // 2005/11/08 : [....] - Created // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; namespace MS.Internal.Ink { internal class DrawingAttributesDefaultValueFactory : DefaultValueFactory { internal DrawingAttributesDefaultValueFactory() { } ////// 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 DrawingAttributes(); } } ////// Creates a mutable default value /// internal override object CreateDefaultValue(DependencyObject owner, DependencyProperty property) { // Instantiate our default value instance. DrawingAttributes defaultValue = new DrawingAttributes(); // Add event handlers for tracking the changes on the default value instance. DrawingAttributesDefaultPromoter promoter = new DrawingAttributesDefaultPromoter((InkCanvas)owner); defaultValue.AttributeChanged += new PropertyDataChangedEventHandler(promoter.OnDrawingAttributesChanged); defaultValue.PropertyDataChanged += new PropertyDataChangedEventHandler(promoter.OnDrawingAttributesChanged); return defaultValue; } ////// A tracking class which monitors the sub-property changes on DrawingAttributes /// private class DrawingAttributesDefaultPromoter { ////// Constructor /// /// internal DrawingAttributesDefaultPromoter(InkCanvas owner) { _owner = owner; } ////// A handler for both AttributeChanged and PropertyDataChanged. /// /// /// internal void OnDrawingAttributesChanged(object sender, PropertyDataChangedEventArgs e) { DrawingAttributes value = (DrawingAttributes)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.AttributeChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); value.PropertyDataChanged -= new PropertyDataChangedEventHandler(OnDrawingAttributesChanged); // NTRAID#WINDOWS-1334059-2005/10/17-waynezen, // We only promote the value when there is no local value set yet. if (_owner.ReadLocalValue(InkCanvas.DefaultDrawingAttributesProperty) == DependencyProperty.UnsetValue) { // Promote the instance to the local value. _owner.SetValue(InkCanvas.DefaultDrawingAttributesProperty, 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 = InkCanvas.DefaultDrawingAttributesProperty.GetMetadata(_owner.DependencyObjectType); metadata.ClearCachedDefaultValue(_owner, InkCanvas.DefaultDrawingAttributesProperty); } private readonly InkCanvas _owner; } } } // 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
- CellTreeNodeVisitors.cs
- ServiceHostFactory.cs
- CultureInfoConverter.cs
- ValidationRuleCollection.cs
- X509Certificate.cs
- DataTableExtensions.cs
- ResourceReferenceExpressionConverter.cs
- CompiledRegexRunner.cs
- SqlDataSourceAdvancedOptionsForm.cs
- Point3D.cs
- SignatureConfirmationElement.cs
- EventHandlers.cs
- HtmlLabelAdapter.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- AutoSizeComboBox.cs
- FullTextLine.cs
- CroppedBitmap.cs
- BatchParser.cs
- XmlSubtreeReader.cs
- TableSectionStyle.cs
- COM2TypeInfoProcessor.cs
- cookiecollection.cs
- HebrewCalendar.cs
- HttpSessionStateBase.cs
- _ScatterGatherBuffers.cs
- LabelLiteral.cs
- Thread.cs
- DebugTrace.cs
- FormatException.cs
- DataListItemEventArgs.cs
- MasterPageBuildProvider.cs
- InteropTrackingRecord.cs
- Transform.cs
- ToolStrip.cs
- InputProcessorProfiles.cs
- PersonalizationDictionary.cs
- BehaviorEditorPart.cs
- SmiEventSink_Default.cs
- EntityFunctions.cs
- PathGeometry.cs
- QilScopedVisitor.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- TypeNameConverter.cs
- _SSPISessionCache.cs
- ConnectionManagementElementCollection.cs
- NamespaceQuery.cs
- LeaseManager.cs
- Int32CAMarshaler.cs
- DataBindingValueUIHandler.cs
- OneToOneMappingSerializer.cs
- TextServicesProperty.cs
- PersonalizationStateInfoCollection.cs
- VsPropertyGrid.cs
- Types.cs
- SqlHelper.cs
- SmtpLoginAuthenticationModule.cs
- Mappings.cs
- TimeSpanValidatorAttribute.cs
- SvcMapFile.cs
- GroupQuery.cs
- RelationshipDetailsRow.cs
- StringValueSerializer.cs
- PointCollection.cs
- ScrollProviderWrapper.cs
- FormViewInsertedEventArgs.cs
- RegexCharClass.cs
- Stroke2.cs
- XmlNodeChangedEventArgs.cs
- Column.cs
- TransactionManagerProxy.cs
- FamilyCollection.cs
- ProfilePropertySettings.cs
- SystemKeyConverter.cs
- DataGridViewSortCompareEventArgs.cs
- MachineKeyConverter.cs
- FlowDocumentView.cs
- SafeEventHandle.cs
- PageBuildProvider.cs
- WsatStrings.cs
- StateMachine.cs
- StreamGeometryContext.cs
- PrintPreviewDialog.cs
- ChangePassword.cs
- DataViewManagerListItemTypeDescriptor.cs
- RegexBoyerMoore.cs
- StandardCommands.cs
- CustomErrorsSection.cs
- WebPartManagerInternals.cs
- ISessionStateStore.cs
- RemotingConfiguration.cs
- WindowsIdentity.cs
- CriticalHandle.cs
- BulletDecorator.cs
- CounterCreationDataCollection.cs
- GuidTagList.cs
- XmlNamespaceMapping.cs
- DetailsViewDeletedEventArgs.cs
- TrackingExtract.cs
- EditingMode.cs
- XmlComplianceUtil.cs