Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Base / System / Collections / Specialized / CollectionChangedEventManager.cs / 1 / CollectionChangedEventManager.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description: Manager for the CollectionChanged event in the "weak event listener"
// pattern. See WeakEventTable.cs for an overview.
//
//---------------------------------------------------------------------------
using System;
using System.Windows; // WeakEventManager
namespace System.Collections.Specialized
{
///
/// Manager for the INotifyCollectionChanged.CollectionChanged event.
///
public class CollectionChangedEventManager : WeakEventManager
{
#region Constructors
//
// Constructors
//
private CollectionChangedEventManager()
{
}
#endregion Constructors
#region Public Methods
//
// Public Methods
//
///
/// Add a listener to the given source's event.
///
public static void AddListener(INotifyCollectionChanged source, IWeakEventListener listener)
{
CurrentManager.ProtectedAddListener(source, listener);
}
///
/// Remove a listener to the given source's event.
///
public static void RemoveListener(INotifyCollectionChanged 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)
{
INotifyCollectionChanged typedSource = (INotifyCollectionChanged)source;
typedSource.CollectionChanged += new NotifyCollectionChangedEventHandler(OnCollectionChanged);
}
///
/// Stop listening to the given source for the event.
///
protected override void StopListening(object source)
{
INotifyCollectionChanged typedSource = (INotifyCollectionChanged)source;
typedSource.CollectionChanged -= new NotifyCollectionChangedEventHandler(OnCollectionChanged);
}
#endregion Protected Methods
#region Private Properties
//
// Private Properties
//
// get the event manager for the current thread
private static CollectionChangedEventManager CurrentManager
{
get
{
Type managerType = typeof(CollectionChangedEventManager);
CollectionChangedEventManager manager = (CollectionChangedEventManager)GetCurrentManager(managerType);
// at first use, create and register a new manager
if (manager == null)
{
manager = new CollectionChangedEventManager();
SetCurrentManager(managerType, manager);
}
return manager;
}
}
#endregion Private Properties
#region Private Methods
//
// Private Methods
//
// event handler for CollectionChanged event
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs 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
- AnnotationResourceCollection.cs
- SqlMetaData.cs
- ListControlDataBindingHandler.cs
- PropertyGeneratedEventArgs.cs
- Timeline.cs
- StringFreezingAttribute.cs
- HorizontalAlignConverter.cs
- KnownBoxes.cs
- HashMembershipCondition.cs
- GlyphTypeface.cs
- ButtonFieldBase.cs
- EventLogTraceListener.cs
- TabItem.cs
- SQLMoney.cs
- FixedSchema.cs
- TableItemStyle.cs
- HttpFileCollection.cs
- DrawingVisual.cs
- DateTimePicker.cs
- VirtualPath.cs
- SyndicationItemFormatter.cs
- ParseNumbers.cs
- ClientBuildManagerCallback.cs
- NativeMethods.cs
- XmlSchemaImport.cs
- SqlTypesSchemaImporter.cs
- RtfControlWordInfo.cs
- MSAAEventDispatcher.cs
- CompilationRelaxations.cs
- DocumentXmlWriter.cs
- ViewService.cs
- RijndaelManaged.cs
- TypeSemantics.cs
- OletxCommittableTransaction.cs
- DragSelectionMessageFilter.cs
- LogWriteRestartAreaAsyncResult.cs
- HttpSysSettings.cs
- SudsCommon.cs
- PointAnimationUsingKeyFrames.cs
- ServicesUtilities.cs
- Metadata.cs
- DashStyle.cs
- InputBindingCollection.cs
- ToolStripPanelSelectionBehavior.cs
- UnmanagedMemoryStream.cs
- XsltArgumentList.cs
- HwndProxyElementProvider.cs
- ToolStripContainerActionList.cs
- SmtpSection.cs
- SelectionPattern.cs
- OpacityConverter.cs
- DistinctQueryOperator.cs
- AmbientEnvironment.cs
- CodePropertyReferenceExpression.cs
- SystemPens.cs
- SystemNetHelpers.cs
- ElapsedEventArgs.cs
- SendMessageContent.cs
- MSHTMLHost.cs
- PropertyEmitter.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- ManagementBaseObject.cs
- DBBindings.cs
- SimplePropertyEntry.cs
- XmlDataDocument.cs
- StaticResourceExtension.cs
- PropertyChangeTracker.cs
- ItemsControlAutomationPeer.cs
- MILUtilities.cs
- OdbcException.cs
- IisTraceWebEventProvider.cs
- ReadOnlyDataSource.cs
- WebChannelFactory.cs
- DockEditor.cs
- XMLDiffLoader.cs
- AutomationPeer.cs
- SiteMapDataSourceView.cs
- SharedRuntimeState.cs
- TreeViewCancelEvent.cs
- QuaternionConverter.cs
- MetadataArtifactLoaderCompositeFile.cs
- DataObjectMethodAttribute.cs
- PassportIdentity.cs
- FilterEventArgs.cs
- Qualifier.cs
- IteratorFilter.cs
- PeerToPeerException.cs
- EventEntry.cs
- DoubleKeyFrameCollection.cs
- ParameterCollection.cs
- ConfigurationSectionCollection.cs
- CountAggregationOperator.cs
- MimeTypeAttribute.cs
- SqlStream.cs
- Frame.cs
- RecipientInfo.cs
- FileLoadException.cs
- RuntimeHandles.cs
- WebReferencesBuildProvider.cs
- FrameworkElementAutomationPeer.cs