Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / MS / Internal / Ink / DrawingAttributesDefaultValueFactory.cs / 1 / DrawingAttributesDefaultValueFactory.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DefaultValueFactory for DrawingAttributes // // History: // 2005/11/08 : jordanpa - 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 : jordanpa - 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
- ResourcePermissionBaseEntry.cs
- ServiceCredentialsSecurityTokenManager.cs
- XmlSchemaSimpleContentExtension.cs
- SqlUDTStorage.cs
- DocumentSchemaValidator.cs
- FileDialog_Vista.cs
- UrlMapping.cs
- NamespaceCollection.cs
- JsonFormatMapping.cs
- RayMeshGeometry3DHitTestResult.cs
- TagPrefixAttribute.cs
- ServiceRouteHandler.cs
- Propagator.JoinPropagator.cs
- PositiveTimeSpanValidatorAttribute.cs
- ClientSideProviderDescription.cs
- Token.cs
- ZipFileInfoCollection.cs
- StylusPointPropertyInfo.cs
- Quaternion.cs
- StyleXamlParser.cs
- DateTimeFormatInfo.cs
- RegionInfo.cs
- OrElse.cs
- FloatUtil.cs
- RuntimeResourceSet.cs
- NotSupportedException.cs
- DayRenderEvent.cs
- TabItemAutomationPeer.cs
- HandleInitializationContext.cs
- CheckedListBox.cs
- XPathParser.cs
- Section.cs
- SqlParameterCollection.cs
- X509Certificate2Collection.cs
- AnimationClockResource.cs
- CompModSwitches.cs
- PeerNearMe.cs
- LinearQuaternionKeyFrame.cs
- StringInfo.cs
- ISCIIEncoding.cs
- TdsParserHelperClasses.cs
- TableLayoutPanel.cs
- _LocalDataStore.cs
- EntityDataSourceStatementEditorForm.cs
- CdpEqualityComparer.cs
- CommentAction.cs
- ADConnectionHelper.cs
- PolyLineSegment.cs
- EventLogPermissionAttribute.cs
- MenuCommandService.cs
- DelegateHelpers.cs
- KeyValueInternalCollection.cs
- XmlSchemaAnyAttribute.cs
- SafeReversePInvokeHandle.cs
- CollectionBuilder.cs
- Condition.cs
- FormViewUpdatedEventArgs.cs
- RowUpdatedEventArgs.cs
- DeviceSpecificChoice.cs
- Directory.cs
- XmlChildEnumerator.cs
- ResourceCategoryAttribute.cs
- ResolvedKeyFrameEntry.cs
- NullableFloatAverageAggregationOperator.cs
- TextTreeUndoUnit.cs
- RequestCachePolicy.cs
- OdbcHandle.cs
- PeerEndPoint.cs
- ButtonBaseDesigner.cs
- ListViewInsertionMark.cs
- SystemWebSectionGroup.cs
- HttpHeaderCollection.cs
- EntityViewGenerationAttribute.cs
- RelatedView.cs
- XsltCompileContext.cs
- HierarchicalDataSourceConverter.cs
- XmlCustomFormatter.cs
- FixedElement.cs
- Evidence.cs
- HTTPNotFoundHandler.cs
- SqlRemoveConstantOrderBy.cs
- UpdatePanelTrigger.cs
- Binding.cs
- ConfigurationManagerInternalFactory.cs
- ObjectReferenceStack.cs
- DependencyObjectValidator.cs
- CacheDependency.cs
- ComponentTray.cs
- DataGridViewSortCompareEventArgs.cs
- DbModificationCommandTree.cs
- StringSorter.cs
- Ipv6Element.cs
- ViewManager.cs
- SchemaMapping.cs
- SqlCharStream.cs
- EventMappingSettings.cs
- XsltContext.cs
- StrokeNodeEnumerator.cs
- VariableQuery.cs
- PersonalizationProvider.cs