Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / PrePostDescendentsWalker.cs / 1305600 / PrePostDescendentsWalker.cs
//------------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description:
// A simple subclass of DescendentsWalker which introduces a second callback
// which is called after a node's children have been visited.
//
// History:
// 04/13/2004: rruiz: Introduces class.
// 10/20/2004: rruiz: Moved class to MS.Internal.
//
//-----------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Windows;
using MS.Utility;
namespace MS.Internal
{
///
/// A simple subclass of DescendentsWalker which introduces a second callback
/// which is called after a node's children have been visited.
///
internal class PrePostDescendentsWalker : DescendentsWalker
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Creates an instances of PrePostDescendentsWalker.
///
/// specifies which tree should be visited first
/// the callback to be called before a node's children are visited
/// the callback to be called after a node's children are visited
/// the data passed to each callback
public PrePostDescendentsWalker(TreeWalkPriority priority, VisitedCallback preCallback, VisitedCallback postCallback, T data) :
base(priority, preCallback, data)
{
_postCallback = postCallback;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Starts the walking process for the given node.
///
/// the node to start the walk on
/// whether or not the first node should have the callbacks called on it
public override void StartWalk(DependencyObject startNode, bool skipStartNode)
{
try
{
base.StartWalk(startNode, skipStartNode);
}
finally
{
if (!skipStartNode)
{
if (_postCallback != null)
{
// This type checking is done in DescendentsWalker. Doing it here
// keeps us consistent.
if (FrameworkElement.DType.IsInstanceOfType(startNode) || FrameworkContentElement.DType.IsInstanceOfType(startNode))
{
_postCallback(startNode, this.Data);
}
}
}
}
}
#endregion Public Methods
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// This method is called for every node touched during a walking of
/// the tree. Some nodes may not have this called if the preCallback
/// returns false - thereby preventing its subtree from being visited.
///
/// the node to visit
protected override void _VisitNode(DependencyObject d)
{
try
{
base._VisitNode(d);
}
finally
{
if (_postCallback != null)
{
_postCallback(d, this.Data);
}
}
}
#endregion Protected Methods
//-----------------------------------------------------
//
// Private Properties
//
//------------------------------------------------------
#region Private Properties
private VisitedCallback _postCallback;
#endregion Private Properties
}
}
// 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:
// A simple subclass of DescendentsWalker which introduces a second callback
// which is called after a node's children have been visited.
//
// History:
// 04/13/2004: rruiz: Introduces class.
// 10/20/2004: rruiz: Moved class to MS.Internal.
//
//-----------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Windows;
using MS.Utility;
namespace MS.Internal
{
///
/// A simple subclass of DescendentsWalker which introduces a second callback
/// which is called after a node's children have been visited.
///
internal class PrePostDescendentsWalker : DescendentsWalker
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Creates an instances of PrePostDescendentsWalker.
///
/// specifies which tree should be visited first
/// the callback to be called before a node's children are visited
/// the callback to be called after a node's children are visited
/// the data passed to each callback
public PrePostDescendentsWalker(TreeWalkPriority priority, VisitedCallback preCallback, VisitedCallback postCallback, T data) :
base(priority, preCallback, data)
{
_postCallback = postCallback;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Starts the walking process for the given node.
///
/// the node to start the walk on
/// whether or not the first node should have the callbacks called on it
public override void StartWalk(DependencyObject startNode, bool skipStartNode)
{
try
{
base.StartWalk(startNode, skipStartNode);
}
finally
{
if (!skipStartNode)
{
if (_postCallback != null)
{
// This type checking is done in DescendentsWalker. Doing it here
// keeps us consistent.
if (FrameworkElement.DType.IsInstanceOfType(startNode) || FrameworkContentElement.DType.IsInstanceOfType(startNode))
{
_postCallback(startNode, this.Data);
}
}
}
}
}
#endregion Public Methods
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// This method is called for every node touched during a walking of
/// the tree. Some nodes may not have this called if the preCallback
/// returns false - thereby preventing its subtree from being visited.
///
/// the node to visit
protected override void _VisitNode(DependencyObject d)
{
try
{
base._VisitNode(d);
}
finally
{
if (_postCallback != null)
{
_postCallback(d, this.Data);
}
}
}
#endregion Protected Methods
//-----------------------------------------------------
//
// Private Properties
//
//------------------------------------------------------
#region Private Properties
private VisitedCallback _postCallback;
#endregion Private Properties
}
}
// 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
- InputLangChangeRequestEvent.cs
- ScrollContentPresenter.cs
- GeometryGroup.cs
- TargetConverter.cs
- InertiaRotationBehavior.cs
- AdornerLayer.cs
- SafeNativeMethods.cs
- MenuItem.cs
- HttpResponse.cs
- UrlPath.cs
- ZipIOLocalFileDataDescriptor.cs
- Atom10FormatterFactory.cs
- SEHException.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- RSAPKCS1KeyExchangeFormatter.cs
- StateChangeEvent.cs
- ToolStripItemCollection.cs
- ResourceDisplayNameAttribute.cs
- AdCreatedEventArgs.cs
- JapaneseCalendar.cs
- ServiceProviders.cs
- WebBrowserProgressChangedEventHandler.cs
- DocComment.cs
- Control.cs
- ArrangedElementCollection.cs
- DynamicHyperLink.cs
- ReflectTypeDescriptionProvider.cs
- externdll.cs
- OdbcConnectionStringbuilder.cs
- PassportAuthentication.cs
- Color.cs
- StyleSelector.cs
- PasswordBoxAutomationPeer.cs
- PreProcessInputEventArgs.cs
- SessionPageStatePersister.cs
- GraphicsState.cs
- SystemColors.cs
- TableRow.cs
- Currency.cs
- SafeProcessHandle.cs
- XmlAtomErrorReader.cs
- XmlWellformedWriterHelpers.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- DataGridViewRow.cs
- NameValueSectionHandler.cs
- TextDecorationCollectionConverter.cs
- Viewport3DAutomationPeer.cs
- CacheDependency.cs
- TypeGeneratedEventArgs.cs
- ViewService.cs
- ConnectionOrientedTransportElement.cs
- PathGeometry.cs
- XmlBinaryWriter.cs
- MouseEventArgs.cs
- ToolTip.cs
- ThreadStateException.cs
- Vector3DCollection.cs
- WindowsContainer.cs
- EntityKey.cs
- BufferedReceiveManager.cs
- ScriptIgnoreAttribute.cs
- UidManager.cs
- FindCriteria11.cs
- TextReturnReader.cs
- XmlNamespaceManager.cs
- Validator.cs
- Win32PrintDialog.cs
- WebPartDisplayMode.cs
- ContentOperations.cs
- SchemaTypeEmitter.cs
- RightsManagementEncryptedStream.cs
- RadioButton.cs
- FieldMetadata.cs
- FrameworkElementAutomationPeer.cs
- DBSchemaTable.cs
- GridViewRow.cs
- CompilerInfo.cs
- TdsParserStateObject.cs
- GridViewRowPresenter.cs
- CompilerGlobalScopeAttribute.cs
- ConfigXmlComment.cs
- LambdaCompiler.Unary.cs
- ObjectDisposedException.cs
- XmlNamespaceMappingCollection.cs
- ToolStripSettings.cs
- PlaceHolder.cs
- HttpHandlerActionCollection.cs
- BaseAddressPrefixFilterElementCollection.cs
- HeaderedContentControl.cs
- InputMethodStateTypeInfo.cs
- Size.cs
- CalendarBlackoutDatesCollection.cs
- ToolboxItemFilterAttribute.cs
- DocumentViewerBaseAutomationPeer.cs
- ProcessInfo.cs
- ObjectDisposedException.cs
- SqlVersion.cs
- Int32Collection.cs
- ControlDesigner.cs
- TagNameToTypeMapper.cs