Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / Ink / StrokeCollectionDefaultValueFactory.cs / 1 / StrokeCollectionDefaultValueFactory.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DefaultValueFactory for StrokeCollection // // History: // 2006/01/24 : [....] - 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 ); // 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
- ConfigXmlWhitespace.cs
- DataControlCommands.cs
- SqlRowUpdatingEvent.cs
- PassportIdentity.cs
- BitmapFrameEncode.cs
- TimeManager.cs
- EditorBrowsableAttribute.cs
- XmlSchemaAny.cs
- MimeFormatExtensions.cs
- ToolStripPanelRenderEventArgs.cs
- TemplateContentLoader.cs
- AttributeCollection.cs
- ParallelTimeline.cs
- CodeTypeDeclaration.cs
- SafeRightsManagementSessionHandle.cs
- ConfigurationSettings.cs
- XomlCompiler.cs
- Parser.cs
- AnchoredBlock.cs
- SessionIDManager.cs
- TextSchema.cs
- BypassElementCollection.cs
- BindingBase.cs
- WorkflowIdleElement.cs
- ExpressionBuilder.cs
- WhileDesigner.xaml.cs
- CompressStream.cs
- ParameterExpression.cs
- Control.cs
- SelectedGridItemChangedEvent.cs
- BuildResult.cs
- localization.cs
- AttributeUsageAttribute.cs
- HttpHandlersSection.cs
- MultiTrigger.cs
- Menu.cs
- InvalidEnumArgumentException.cs
- RawStylusActions.cs
- MultiView.cs
- Set.cs
- DataTableClearEvent.cs
- TextSpan.cs
- AutoCompleteStringCollection.cs
- FieldAccessException.cs
- MexNamedPipeBindingElement.cs
- NamedPipeHostedTransportConfiguration.cs
- validationstate.cs
- EntitySqlQueryCacheEntry.cs
- ImageSourceValueSerializer.cs
- HtmlShim.cs
- coordinator.cs
- EdmItemError.cs
- ErrorTableItemStyle.cs
- BypassElementCollection.cs
- EditorBrowsableAttribute.cs
- QilScopedVisitor.cs
- StringDictionaryWithComparer.cs
- AudioStateChangedEventArgs.cs
- ZipIOExtraFieldElement.cs
- SortAction.cs
- ExpressionBindingCollection.cs
- HyperLinkColumn.cs
- Clause.cs
- wmiprovider.cs
- SessionIDManager.cs
- SamlSecurityTokenAuthenticator.cs
- DataGridViewCellParsingEventArgs.cs
- COAUTHINFO.cs
- ScriptMethodAttribute.cs
- HybridWebProxyFinder.cs
- InertiaTranslationBehavior.cs
- StorageMappingItemLoader.cs
- XmlILModule.cs
- SourceFileBuildProvider.cs
- BehaviorEditorPart.cs
- LinearKeyFrames.cs
- RawStylusActions.cs
- SqlCrossApplyToCrossJoin.cs
- FixedSOMPageElement.cs
- UIPermission.cs
- DbConnectionPoolGroup.cs
- SizeKeyFrameCollection.cs
- ReadContentAsBinaryHelper.cs
- StringAnimationBase.cs
- ElementNotEnabledException.cs
- SQLInt16Storage.cs
- RsaSecurityKey.cs
- ColumnMapTranslator.cs
- ModelTypeConverter.cs
- FormatterConverter.cs
- ContextMenuStrip.cs
- HtmlImage.cs
- GeneratedContractType.cs
- RtfToken.cs
- EntityDataSourceWrapper.cs
- WindowsBrush.cs
- Int32Collection.cs
- InternalConfigSettingsFactory.cs
- PropertyDescriptorComparer.cs
- TextMessageEncodingBindingElement.cs