Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Base / MS / Internal / InheritanceContextChangedEventManager.cs / 1 / InheritanceContextChangedEventManager.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: Manager for the InheritanceContextChanged event in the "weak event listener" // pattern. See WeakEventTable.cs for an overview. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; // WeakEventManager using MS.Internal.WindowsBase; // [FriendAccessAllowed] namespace MS.Internal { ////// Manager for the DependencyObject.InheritanceContextChanged event. /// [FriendAccessAllowed] internal class InheritanceContextChangedEventManager : WeakEventManager { #region Constructors // // Constructors // private InheritanceContextChangedEventManager() { } #endregion Constructors #region Public Methods // // Public Methods // ////// Add a listener to the given source's event. /// public static void AddListener(DependencyObject source, IWeakEventListener listener) { // Freezable.Freeze() relies on the assumption that a frozen Freezable // has no listeners. This is because Freeze() fails if the Freezable // has any Expressions on it, and only Expressions ever listen // to the InheritanceContextChanged event. Debug.Assert(listener is Expression); CurrentManager.ProtectedAddListener(source, listener); } ////// Remove a listener to the given source's event. /// public static void RemoveListener(DependencyObject source, IWeakEventListener listener) { CurrentManager.ProtectedRemoveListener(source, listener); } #endregion Public Methods #region Protected Methods // // Protected Methods // ////// Listen to the given source for the event. /// protected override void StartListening(object source) { DependencyObject typedSource = (DependencyObject)source; typedSource.InheritanceContextChanged += new EventHandler(OnInheritanceContextChanged); } ////// Stop listening to the given source for the event. /// protected override void StopListening(object source) { DependencyObject typedSource = (DependencyObject)source; typedSource.InheritanceContextChanged -= new EventHandler(OnInheritanceContextChanged); } #endregion Protected Methods #region Private Properties // // Private Properties // // get the event manager for the current thread private static InheritanceContextChangedEventManager CurrentManager { get { Type managerType = typeof(InheritanceContextChangedEventManager); InheritanceContextChangedEventManager manager = (InheritanceContextChangedEventManager)GetCurrentManager(managerType); // at first use, create and register a new manager if (manager == null) { manager = new InheritanceContextChangedEventManager(); SetCurrentManager(managerType, manager); } return manager; } } #endregion Private Properties #region Private Methods // // Private Methods // // event handler for InheritanceContextChanged event private void OnInheritanceContextChanged(object sender, EventArgs args) { DeliverEvent(sender, args); } #endregion Private Methods } } // 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: Manager for the InheritanceContextChanged event in the "weak event listener" // pattern. See WeakEventTable.cs for an overview. // //--------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Windows; // WeakEventManager using MS.Internal.WindowsBase; // [FriendAccessAllowed] namespace MS.Internal { ////// Manager for the DependencyObject.InheritanceContextChanged event. /// [FriendAccessAllowed] internal class InheritanceContextChangedEventManager : WeakEventManager { #region Constructors // // Constructors // private InheritanceContextChangedEventManager() { } #endregion Constructors #region Public Methods // // Public Methods // ////// Add a listener to the given source's event. /// public static void AddListener(DependencyObject source, IWeakEventListener listener) { // Freezable.Freeze() relies on the assumption that a frozen Freezable // has no listeners. This is because Freeze() fails if the Freezable // has any Expressions on it, and only Expressions ever listen // to the InheritanceContextChanged event. Debug.Assert(listener is Expression); CurrentManager.ProtectedAddListener(source, listener); } ////// Remove a listener to the given source's event. /// public static void RemoveListener(DependencyObject source, IWeakEventListener listener) { CurrentManager.ProtectedRemoveListener(source, listener); } #endregion Public Methods #region Protected Methods // // Protected Methods // ////// Listen to the given source for the event. /// protected override void StartListening(object source) { DependencyObject typedSource = (DependencyObject)source; typedSource.InheritanceContextChanged += new EventHandler(OnInheritanceContextChanged); } ////// Stop listening to the given source for the event. /// protected override void StopListening(object source) { DependencyObject typedSource = (DependencyObject)source; typedSource.InheritanceContextChanged -= new EventHandler(OnInheritanceContextChanged); } #endregion Protected Methods #region Private Properties // // Private Properties // // get the event manager for the current thread private static InheritanceContextChangedEventManager CurrentManager { get { Type managerType = typeof(InheritanceContextChangedEventManager); InheritanceContextChangedEventManager manager = (InheritanceContextChangedEventManager)GetCurrentManager(managerType); // at first use, create and register a new manager if (manager == null) { manager = new InheritanceContextChangedEventManager(); SetCurrentManager(managerType, manager); } return manager; } } #endregion Private Properties #region Private Methods // // Private Methods // // event handler for InheritanceContextChanged event private void OnInheritanceContextChanged(object sender, EventArgs args) { DeliverEvent(sender, args); } #endregion Private Methods } } // 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
- XmlSchemaSimpleType.cs
- FtpRequestCacheValidator.cs
- SqlBooleanMismatchVisitor.cs
- SkewTransform.cs
- NotifyIcon.cs
- EncryptedXml.cs
- XmlSchemaCollection.cs
- BaseServiceProvider.cs
- CustomErrorCollection.cs
- Propagator.JoinPropagator.cs
- RelationshipEntry.cs
- Soap12ProtocolImporter.cs
- ConnectionPoint.cs
- _SafeNetHandles.cs
- CapabilitiesSection.cs
- ImageMap.cs
- ToolStripGripRenderEventArgs.cs
- DataGridTextBoxColumn.cs
- ReflectTypeDescriptionProvider.cs
- hwndwrapper.cs
- _RequestCacheProtocol.cs
- TextViewBase.cs
- WorkflowViewElement.cs
- StorageFunctionMapping.cs
- AttachedPropertiesService.cs
- XPathMessageFilter.cs
- ApplicationSecurityManager.cs
- GcHandle.cs
- XmlNode.cs
- DBSchemaRow.cs
- ExpressionParser.cs
- WebBrowserContainer.cs
- SqlTriggerAttribute.cs
- CrossAppDomainChannel.cs
- WebPartConnectionCollection.cs
- KeyboardEventArgs.cs
- RtfToXamlLexer.cs
- TextElementEditingBehaviorAttribute.cs
- BindingListCollectionView.cs
- HtmlWindow.cs
- TreeViewCancelEvent.cs
- MappingMetadataHelper.cs
- COMException.cs
- DocumentGridContextMenu.cs
- PkcsMisc.cs
- LogFlushAsyncResult.cs
- Compiler.cs
- SqlError.cs
- ToolStripDropTargetManager.cs
- InitializationEventAttribute.cs
- PatternMatcher.cs
- TempFiles.cs
- GenericsNotImplementedException.cs
- SchemaElementDecl.cs
- DataGridViewCellParsingEventArgs.cs
- EnumConverter.cs
- CustomTypeDescriptor.cs
- DragDeltaEventArgs.cs
- dataSvcMapFileLoader.cs
- RowsCopiedEventArgs.cs
- EnumValidator.cs
- RichTextBoxAutomationPeer.cs
- Converter.cs
- SqlCacheDependencySection.cs
- FixedSOMGroup.cs
- BindingMAnagerBase.cs
- WindowsGraphicsCacheManager.cs
- PointLightBase.cs
- Brushes.cs
- Zone.cs
- StreamResourceInfo.cs
- SqlGenerator.cs
- AngleUtil.cs
- RightsManagementPermission.cs
- CodeAttributeDeclaration.cs
- TransformCollection.cs
- XPathQilFactory.cs
- XmlDocumentFragment.cs
- FormsIdentity.cs
- CompleteWizardStep.cs
- InternalConfigHost.cs
- DependencyObjectPropertyDescriptor.cs
- OrCondition.cs
- Visual.cs
- UpWmlMobileTextWriter.cs
- MemberHolder.cs
- RandomNumberGenerator.cs
- XmlSchemaSimpleContent.cs
- MetadataCache.cs
- SafeRegistryHandle.cs
- ObjectQueryState.cs
- EncryptedKeyIdentifierClause.cs
- StylusPointPropertyUnit.cs
- CheckedListBox.cs
- PointCollection.cs
- CalloutQueueItem.cs
- NumericUpDown.cs
- DbgCompiler.cs
- XPathSingletonIterator.cs
- QueryOutputWriter.cs