Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- ToolStripItemRenderEventArgs.cs
- ItemAutomationPeer.cs
- DrawingContextDrawingContextWalker.cs
- MsmqHostedTransportManager.cs
- BuildDependencySet.cs
- IODescriptionAttribute.cs
- FixedSOMSemanticBox.cs
- RegexRunner.cs
- SystemIPInterfaceStatistics.cs
- WsdlInspector.cs
- SQLInt32.cs
- CryptoProvider.cs
- ProfileEventArgs.cs
- WpfKnownTypeInvoker.cs
- DiscoveryClientRequestChannel.cs
- ExpressionEditor.cs
- UserNameSecurityTokenAuthenticator.cs
- X509ServiceCertificateAuthenticationElement.cs
- HttpCachePolicyBase.cs
- DataControlLinkButton.cs
- _Win32.cs
- DataControlFieldHeaderCell.cs
- TextDecoration.cs
- QueryExpression.cs
- DataGrid.cs
- NonSerializedAttribute.cs
- LicenseContext.cs
- FixedSOMTable.cs
- HtmlInputControl.cs
- CodeGotoStatement.cs
- NativeStructs.cs
- ExpressionVisitor.cs
- TypeUtil.cs
- UnmanagedHandle.cs
- PassportPrincipal.cs
- DataTableNewRowEvent.cs
- SoapBinding.cs
- BitmapFrameEncode.cs
- TemplateControlBuildProvider.cs
- PerformanceCounterPermission.cs
- DataGridViewButtonColumn.cs
- OdbcConnection.cs
- XPathSelfQuery.cs
- ScaleTransform3D.cs
- ForEachAction.cs
- MenuItem.cs
- OdbcHandle.cs
- CalculatedColumn.cs
- altserialization.cs
- CollectionChangedEventManager.cs
- TraceContextEventArgs.cs
- brushes.cs
- StatusBarPanelClickEvent.cs
- GZipStream.cs
- SQLMoneyStorage.cs
- XPathNodeList.cs
- BitmapEffectGeneralTransform.cs
- SocketSettings.cs
- ConfigXmlText.cs
- RoutedCommand.cs
- EmptyStringExpandableObjectConverter.cs
- PropertyNames.cs
- SendingRequestEventArgs.cs
- NotFiniteNumberException.cs
- XmlSchemaExporter.cs
- Route.cs
- ModelEditingScope.cs
- SystemResourceKey.cs
- ContextMenuAutomationPeer.cs
- XmlEntity.cs
- HighContrastHelper.cs
- ArithmeticException.cs
- CodeGroup.cs
- Knowncolors.cs
- HtmlElementCollection.cs
- QueueProcessor.cs
- SqlAliaser.cs
- TimeEnumHelper.cs
- PolicyChain.cs
- ComponentDesigner.cs
- ContentIterators.cs
- SuppressIldasmAttribute.cs
- ArrangedElementCollection.cs
- GridView.cs
- DBAsyncResult.cs
- RoutedUICommand.cs
- TextContainerChangedEventArgs.cs
- GridToolTip.cs
- DoubleAnimationUsingPath.cs
- XmlUnspecifiedAttribute.cs
- EmptyCollection.cs
- DbConnectionClosed.cs
- SafeSecurityHandles.cs
- XmlSchemaExporter.cs
- WebPartDeleteVerb.cs
- DataGridViewBindingCompleteEventArgs.cs
- SortFieldComparer.cs
- MessageProperties.cs
- AudioException.cs
- ISAPIApplicationHost.cs