Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- TreeNodeEventArgs.cs
- SqlExpander.cs
- TransportListener.cs
- Funcletizer.cs
- SafeLocalAllocation.cs
- WmpBitmapEncoder.cs
- DataServiceHost.cs
- SafeFindHandle.cs
- InitiatorServiceModelSecurityTokenRequirement.cs
- Graph.cs
- DecimalConverter.cs
- Utils.cs
- ClassHandlersStore.cs
- BufferedOutputStream.cs
- HGlobalSafeHandle.cs
- ResourceProperty.cs
- BitmapCache.cs
- DocumentGrid.cs
- HtmlInputReset.cs
- DocumentApplicationJournalEntry.cs
- Encoder.cs
- IndentedTextWriter.cs
- Crypto.cs
- GridItemProviderWrapper.cs
- ExclusiveHandleList.cs
- SizeAnimationUsingKeyFrames.cs
- ColumnWidthChangedEvent.cs
- FunctionDetailsReader.cs
- TextParaLineResult.cs
- OneToOneMappingSerializer.cs
- NavigatorOutput.cs
- DataControlButton.cs
- PersonalizationAdministration.cs
- WebHttpBehavior.cs
- TextRenderingModeValidation.cs
- BaseDataBoundControl.cs
- ItemDragEvent.cs
- RegexGroup.cs
- CuspData.cs
- MasterPageBuildProvider.cs
- WhitespaceRuleReader.cs
- altserialization.cs
- MobileUserControlDesigner.cs
- Executor.cs
- EntityDataSourceDataSelection.cs
- ParameterToken.cs
- ActivityTypeCodeDomSerializer.cs
- DataTableNewRowEvent.cs
- CompilerHelpers.cs
- _OverlappedAsyncResult.cs
- ConnectionPoolManager.cs
- URLAttribute.cs
- PropertyGeneratedEventArgs.cs
- PrimitiveDataContract.cs
- EventRoute.cs
- WebPartCatalogAddVerb.cs
- BuildDependencySet.cs
- BooleanFunctions.cs
- CompilerState.cs
- DictionaryContent.cs
- PropertyEmitterBase.cs
- SupportsPreviewControlAttribute.cs
- XslAstAnalyzer.cs
- RectangleHotSpot.cs
- SafeRightsManagementEnvironmentHandle.cs
- GlobalDataBindingHandler.cs
- securitycriticaldataformultiplegetandset.cs
- GlyphInfoList.cs
- Subtree.cs
- MissingManifestResourceException.cs
- XmlCharacterData.cs
- HebrewCalendar.cs
- OuterProxyWrapper.cs
- MethodBuilder.cs
- ContextStaticAttribute.cs
- XmlElement.cs
- Int32Storage.cs
- NamedPipeChannelFactory.cs
- XmlBinaryWriter.cs
- EventEntry.cs
- HttpPostServerProtocol.cs
- XmlSchemaObject.cs
- WorkflowQueue.cs
- Site.cs
- XmlILIndex.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- WmlImageAdapter.cs
- ISAPIRuntime.cs
- ErrorFormatterPage.cs
- SynchronizingStream.cs
- TypefaceMap.cs
- PointIndependentAnimationStorage.cs
- DeobfuscatingStream.cs
- EarlyBoundInfo.cs
- XmlParserContext.cs
- TextElementCollectionHelper.cs
- ItemDragEvent.cs
- TextEndOfParagraph.cs
- CreateUserWizard.cs
- MappingSource.cs