Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / MS / Internal / DeferredElementTreeState.cs / 1 / DeferredElementTreeState.cs
using System.Windows;
using System.Collections.Generic;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace MS.Internal
{
internal class DeferredElementTreeState
{
public void SetCoreParent(DependencyObject element, DependencyObject parent)
{
if(!_oldCoreParents.ContainsKey(element))
{
_oldCoreParents[element] = parent;
}
}
public static DependencyObject GetCoreParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = null;
if(treeState != null && treeState._oldCoreParents.ContainsKey(element))
{
parent = treeState._oldCoreParents[element];
}
else
{
Visual v = element as Visual;
if(v != null)
{
parent = VisualTreeHelper.GetParent(v);
}
else
{
ContentElement ce = element as ContentElement;
if(ce != null)
{
parent = ContentOperations.GetParent(ce);
}
else
{
Visual3D v3D = element as Visual3D;
if (v3D != null)
{
parent = VisualTreeHelper.GetParent(v3D);
}
}
}
}
return parent;
}
public static DependencyObject GetInputElementParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = element;
while (true)
{
parent = GetCoreParent(parent, treeState);
if (parent == null || InputElement.IsValid(parent))
{
break;
}
}
return parent;
}
public void SetLogicalParent(DependencyObject element, DependencyObject parent)
{
if(!_oldLogicalParents.ContainsKey(element))
{
_oldLogicalParents[element] = parent;
}
}
public static DependencyObject GetLogicalParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = null;
if(treeState != null && treeState._oldLogicalParents.ContainsKey(element))
{
parent = treeState._oldLogicalParents[element];
}
else
{
UIElement e = element as UIElement;
if(e != null)
{
parent = e.GetUIParentCore(); // Overriden by FrameworkElement.
}
ContentElement ce = element as ContentElement;
if(ce != null)
{
parent = ce.GetUIParentCore(); // Overriden by FrameworkContentElement.
}
}
return parent;
}
public void Clear()
{
_oldCoreParents.Clear();
_oldLogicalParents.Clear();
}
public bool IsEmpty
{
get
{
return _oldCoreParents.Count > 0 || _oldLogicalParents.Count > 0;
}
}
private Dictionary _oldCoreParents = new Dictionary();
private Dictionary _oldLogicalParents = new Dictionary();
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System.Windows;
using System.Collections.Generic;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace MS.Internal
{
internal class DeferredElementTreeState
{
public void SetCoreParent(DependencyObject element, DependencyObject parent)
{
if(!_oldCoreParents.ContainsKey(element))
{
_oldCoreParents[element] = parent;
}
}
public static DependencyObject GetCoreParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = null;
if(treeState != null && treeState._oldCoreParents.ContainsKey(element))
{
parent = treeState._oldCoreParents[element];
}
else
{
Visual v = element as Visual;
if(v != null)
{
parent = VisualTreeHelper.GetParent(v);
}
else
{
ContentElement ce = element as ContentElement;
if(ce != null)
{
parent = ContentOperations.GetParent(ce);
}
else
{
Visual3D v3D = element as Visual3D;
if (v3D != null)
{
parent = VisualTreeHelper.GetParent(v3D);
}
}
}
}
return parent;
}
public static DependencyObject GetInputElementParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = element;
while (true)
{
parent = GetCoreParent(parent, treeState);
if (parent == null || InputElement.IsValid(parent))
{
break;
}
}
return parent;
}
public void SetLogicalParent(DependencyObject element, DependencyObject parent)
{
if(!_oldLogicalParents.ContainsKey(element))
{
_oldLogicalParents[element] = parent;
}
}
public static DependencyObject GetLogicalParent(DependencyObject element, DeferredElementTreeState treeState)
{
DependencyObject parent = null;
if(treeState != null && treeState._oldLogicalParents.ContainsKey(element))
{
parent = treeState._oldLogicalParents[element];
}
else
{
UIElement e = element as UIElement;
if(e != null)
{
parent = e.GetUIParentCore(); // Overriden by FrameworkElement.
}
ContentElement ce = element as ContentElement;
if(ce != null)
{
parent = ce.GetUIParentCore(); // Overriden by FrameworkContentElement.
}
}
return parent;
}
public void Clear()
{
_oldCoreParents.Clear();
_oldLogicalParents.Clear();
}
public bool IsEmpty
{
get
{
return _oldCoreParents.Count > 0 || _oldLogicalParents.Count > 0;
}
}
private Dictionary _oldCoreParents = new Dictionary();
private Dictionary _oldLogicalParents = new Dictionary();
}
}
// 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
- SqlNotificationRequest.cs
- WindowsFormsEditorServiceHelper.cs
- FtpCachePolicyElement.cs
- XsdBuilder.cs
- TextBox.cs
- PageEventArgs.cs
- PathSegment.cs
- Lazy.cs
- HttpRequest.cs
- Calendar.cs
- Profiler.cs
- PageEventArgs.cs
- NestedContainer.cs
- MinMaxParagraphWidth.cs
- DateTimeConverter.cs
- ModifiableIteratorCollection.cs
- PartitionResolver.cs
- WorkflowTraceTransfer.cs
- DataGridDetailsPresenterAutomationPeer.cs
- Attributes.cs
- SessionIDManager.cs
- DesignTimeValidationFeature.cs
- FileLoadException.cs
- arclist.cs
- DefaultTypeArgumentAttribute.cs
- RenderCapability.cs
- DbConnectionHelper.cs
- DefaultDialogButtons.cs
- XmlSchemaAppInfo.cs
- dbenumerator.cs
- DecimalAnimation.cs
- DataTableTypeConverter.cs
- PageTrueTypeFont.cs
- ClientConvert.cs
- DataGridClipboardCellContent.cs
- DesignerUtils.cs
- DBSqlParserTableCollection.cs
- TransformerTypeCollection.cs
- ChannelReliableSession.cs
- TimeZoneNotFoundException.cs
- ContractSearchPattern.cs
- TextElementEnumerator.cs
- JsonDataContract.cs
- QilUnary.cs
- DSASignatureDeformatter.cs
- LogLogRecordHeader.cs
- KeyValuePairs.cs
- DBSchemaRow.cs
- ThreadAttributes.cs
- DeferredReference.cs
- ValidationHelper.cs
- UmAlQuraCalendar.cs
- PeerNameRecordCollection.cs
- securitycriticaldata.cs
- AvTrace.cs
- DefaultWorkflowTransactionService.cs
- SchemaCollectionCompiler.cs
- Model3D.cs
- UnauthorizedAccessException.cs
- CompositeFontParser.cs
- ContentIterators.cs
- SqlDeflator.cs
- ObjectStateFormatter.cs
- FormViewPageEventArgs.cs
- MenuCommand.cs
- DocumentsTrace.cs
- ContractMapping.cs
- cryptoapiTransform.cs
- PingOptions.cs
- RectangleHotSpot.cs
- OptimalTextSource.cs
- HtmlButton.cs
- HashCryptoHandle.cs
- TransactionsSectionGroup.cs
- HttpCapabilitiesEvaluator.cs
- MultipleViewProviderWrapper.cs
- VBIdentifierTrimConverter.cs
- StreamUpdate.cs
- Lease.cs
- AutoGeneratedField.cs
- DataGridTable.cs
- MetadataCache.cs
- ScrollProviderWrapper.cs
- WebBrowserBase.cs
- SQLBytesStorage.cs
- EllipseGeometry.cs
- XamlInt32CollectionSerializer.cs
- StrongNameIdentityPermission.cs
- PersistenceTypeAttribute.cs
- QilChoice.cs
- FixedBufferAttribute.cs
- CompatibleIComparer.cs
- ConsoleCancelEventArgs.cs
- Geometry3D.cs
- SkipQueryOptionExpression.cs
- ActivityExecutionContextCollection.cs
- DockingAttribute.cs
- SortedSet.cs
- DBDataPermissionAttribute.cs
- SQLBytes.cs