Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Ink / StrokeCollectionDefaultValueFactory.cs / 1305600 / 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
- Resources.Designer.cs
- AlternationConverter.cs
- NetSectionGroup.cs
- PerformanceCounterManager.cs
- ProxyAttribute.cs
- WMICapabilities.cs
- PathFigureCollection.cs
- DebugView.cs
- ObjectDataSourceFilteringEventArgs.cs
- LineMetrics.cs
- FileUtil.cs
- BinaryFormatter.cs
- SymbolType.cs
- ThousandthOfEmRealDoubles.cs
- UInt64Converter.cs
- __ComObject.cs
- ContainerVisual.cs
- TrustLevelCollection.cs
- TypeForwardedToAttribute.cs
- WindowsFormsLinkLabel.cs
- ScriptIgnoreAttribute.cs
- BindingList.cs
- RuleSettingsCollection.cs
- login.cs
- AtomContentProperty.cs
- AssociationSetEnd.cs
- DataSourceUtil.cs
- UIElement.cs
- FileSecurity.cs
- ListSortDescription.cs
- CrossSiteScriptingValidation.cs
- FindCriteria11.cs
- LocalClientSecuritySettings.cs
- Columns.cs
- VirtualizingPanel.cs
- x509utils.cs
- ResourceDefaultValueAttribute.cs
- Clipboard.cs
- PersonalizableTypeEntry.cs
- AssemblyResourceLoader.cs
- DependentList.cs
- Point3DValueSerializer.cs
- JapaneseLunisolarCalendar.cs
- PlatformNotSupportedException.cs
- Compensation.cs
- StrokeDescriptor.cs
- XmlSchemaComplexContent.cs
- ISAPIApplicationHost.cs
- CustomTypeDescriptor.cs
- CryptoKeySecurity.cs
- MDIClient.cs
- ClickablePoint.cs
- MachineSettingsSection.cs
- StyleCollection.cs
- FamilyTypeface.cs
- SubpageParaClient.cs
- DataGridViewRowsRemovedEventArgs.cs
- WebPartHelpVerb.cs
- KeyboardNavigation.cs
- FixUp.cs
- DataSourceControlBuilder.cs
- TemplateContent.cs
- KeyValueConfigurationElement.cs
- SettingsPropertyWrongTypeException.cs
- TableRowCollection.cs
- CodeDomSerializationProvider.cs
- TemplateXamlTreeBuilder.cs
- DataGridViewHeaderCell.cs
- SQLBinary.cs
- ContactManager.cs
- ExceptionHelpers.cs
- ResourceDisplayNameAttribute.cs
- UrlMapping.cs
- DesignerCategoryAttribute.cs
- PriorityChain.cs
- XmlElementAttributes.cs
- MarkupCompilePass2.cs
- TextTreeRootNode.cs
- TailCallAnalyzer.cs
- FacetValueContainer.cs
- ValidateNames.cs
- ExtractorMetadata.cs
- ConfigurationPropertyAttribute.cs
- BindingManagerDataErrorEventArgs.cs
- CodeRemoveEventStatement.cs
- ArgumentOutOfRangeException.cs
- AssemblyResourceLoader.cs
- ComPlusSynchronizationContext.cs
- WebPartAuthorizationEventArgs.cs
- CurrencyManager.cs
- HijriCalendar.cs
- Misc.cs
- RankException.cs
- ListViewDeletedEventArgs.cs
- xml.cs
- HexParser.cs
- OperationInfoBase.cs
- XmlSerializerVersionAttribute.cs
- TcpChannelHelper.cs
- PersistChildrenAttribute.cs