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 / 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
- InfiniteTimeSpanConverter.cs
- HttpInputStream.cs
- TableLayoutSettingsTypeConverter.cs
- CommandField.cs
- RangeValidator.cs
- SqlDataSourceSelectingEventArgs.cs
- TextServicesProperty.cs
- PatternMatcher.cs
- RuntimeHandles.cs
- MediaTimeline.cs
- NamedPipeWorkerProcess.cs
- MaskedTextBox.cs
- DataGridViewColumnEventArgs.cs
- XmlDeclaration.cs
- wmiprovider.cs
- DiffuseMaterial.cs
- ObjectDisposedException.cs
- ConfigurationSectionGroup.cs
- __Filters.cs
- CompilerParameters.cs
- DeviceContext.cs
- CodeExpressionCollection.cs
- CellTreeNode.cs
- CompilerError.cs
- ByteFacetDescriptionElement.cs
- AppliedDeviceFiltersDialog.cs
- OutputScopeManager.cs
- InvalidComObjectException.cs
- PropertyCondition.cs
- SubpageParagraph.cs
- _HeaderInfo.cs
- DbConnectionPoolCounters.cs
- SettingsPropertyValue.cs
- SqlMetaData.cs
- MailAddressCollection.cs
- ValueTypeFixupInfo.cs
- FacetChecker.cs
- ColorTransformHelper.cs
- RoutedEventHandlerInfo.cs
- Point3DConverter.cs
- TextFormatterImp.cs
- TreeIterators.cs
- _ProxyRegBlob.cs
- TableStyle.cs
- ToolStripScrollButton.cs
- DescendantOverDescendantQuery.cs
- HashAlgorithm.cs
- AssemblyCollection.cs
- EntityDesignerUtils.cs
- SqlWebEventProvider.cs
- ListItemViewAttribute.cs
- ContextDataSourceView.cs
- ResolveCriteria.cs
- ResourcesChangeInfo.cs
- WsiProfilesElementCollection.cs
- GetLastErrorDetailsRequest.cs
- DbExpressionBuilder.cs
- AppSettingsExpressionBuilder.cs
- PopupRoot.cs
- SemanticBasicElement.cs
- SqlCachedBuffer.cs
- Compiler.cs
- Operand.cs
- HtmlDocument.cs
- GridViewColumnHeader.cs
- GACIdentityPermission.cs
- ColorConvertedBitmapExtension.cs
- Inflater.cs
- WsdlBuildProvider.cs
- FormViewModeEventArgs.cs
- GroupBoxRenderer.cs
- Repeater.cs
- NavigationHelper.cs
- ChannelCacheSettings.cs
- ContextMenuAutomationPeer.cs
- SoapReflectionImporter.cs
- AssemblyBuilder.cs
- UserNamePasswordValidator.cs
- EntityKey.cs
- HighlightComponent.cs
- BaseAppDomainProtocolHandler.cs
- GenericWebPart.cs
- DesignerDataSchemaClass.cs
- Int32.cs
- TextRangeProviderWrapper.cs
- WindowsSolidBrush.cs
- AssemblyHash.cs
- XmlTextReader.cs
- DataObjectSettingDataEventArgs.cs
- ChtmlCalendarAdapter.cs
- Label.cs
- SqlConnectionHelper.cs
- ResourceExpressionBuilder.cs
- XappLauncher.cs
- Marshal.cs
- ContentFilePart.cs
- ListContractAdapter.cs
- CompModSwitches.cs
- HttpListenerException.cs
- MenuScrollingVisibilityConverter.cs