本文整理汇总了C#中System.Windows.DependencyObject.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetHashCode方法的具体用法?C# DependencyObject.GetHashCode怎么用?C# DependencyObject.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetHashCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElementByHashCode
/// <summary>
/// Searchs an element in the visual tree matching with the given hash code.
/// </summary>
/// <param name="obj">A element in the visual tree as root element to search downwards the tree.</param>
/// <param name="hashCode">The hash code to search for.</param>
/// <returns>The element in the visual three matching the given hash code, otherwise null</returns>
/// <remarks>
/// This method is especially used in case where the visual tree is not part of the
/// main visual tree of the Silverlight application, as it happen with popup controls.
/// Optain the hash code from the output of WriteDownwards/WriteUpwards.
/// </remarks>
public static DependencyObject GetElementByHashCode(DependencyObject obj, int hashCode)
{
if (obj == null)
return null;
// check if hash code matches
if (obj.GetHashCode() == hashCode)
return obj;
// store child count local
int childCount = VisualTreeHelper.GetChildrenCount(obj);
// check if one of the child match to the hash code
for (int i = 0; i < childCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child.GetHashCode() == hashCode)
return child;
}
// go down the tree
for (int i = 0; i < childCount; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
DependencyObject returnObj = GetElementByHashCode(child, hashCode);
// if object was found, return
if (returnObj != null)
return returnObj;
}
// nothing found
return null;
}
示例2: LocalizedProperty
/// <summary>
/// Initializes a new instance of the <see cref="ObjectValue"/> class.
/// </summary>
/// <param name="targetObject">The owner of the property.</param>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="property"/> is <c>null</c>.</exception>
protected LocalizedProperty(DependencyObject obj, object property)
{
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (property == null)
{
throw new ArgumentNullException("property");
}
_object = new WeakReference(obj);
Property = property;
_hashCode = obj.GetHashCode() ^ property.GetHashCode();
}
示例3: CollectTreeUp
/// <summary>
/// Walks up the tree from the given object and collects tree information.
/// </summary>
private static void CollectTreeUp(DependencyObject obj, List<string> levels)
{
if (obj == null)
return;
// name of type
string node = GetTypeName(obj);
// XAML name
node += " " + GetElementName(obj);
// hashcode
node += " " + obj.GetHashCode();
// add level
levels.Add(node);
// follow parent
CollectTreeUp(VisualTreeHelper.GetParent(obj), levels);
}
示例4: CollectTreeDown
/// <summary>
/// Walks down the tree from the given object and collects tree information.
/// </summary>
private static void CollectTreeDown(DependencyObject obj, StringBuilder output, int level, Stack<int> treeLineIndexes, int propertyIntend, ref int visualElementCount)
{
if (obj == null)
return;
// count visual elements
visualElementCount++;
// prepare intend/treelines
string intend = "";
for (int i = 0; i < level; i++)
{
if (treeLineIndexes.Contains(i) || i + 1 >= level)
intend += " |";
else
intend += " ";
}
// type name
string typeName = GetTypeName(obj);
output.Append(intend + "-" + typeName);
output.Append(GetIntendString(propertyIntend - typeName.Length));
// XAML name
output.Append(" " + GetElementName(obj));
// hashcode
output.Append(" " + obj.GetHashCode());
output.Append(" " + GetProperties(obj));
output.Append(Environment.NewLine);
// get child count
int childCount = VisualTreeHelper.GetChildrenCount(obj);
// remember treeline if more than one child
if (childCount >= 2)
treeLineIndexes.Push(level);
int levelForChildTree = ++level;
int lastChildIncludedInIntend = -1;
int intendForChild = 0;
for (int i = 0; i < childCount; i++)
{
// remove the treeline for last element
if (childCount >= 2 && i + 1 == childCount)
treeLineIndexes.Pop();
if (lastChildIncludedInIntend < i)
lastChildIncludedInIntend = GetPropertyValueIntend(obj, i, out intendForChild);
// follow the child
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
CollectTreeDown(child, output, levelForChildTree, treeLineIndexes, intendForChild, ref visualElementCount);
}
}
示例5: ClearContainerForItemOverride
/// <summary>
/// Undoes the effects of the <see cref="ItemsControl.PrepareContainerForItemOverride(System.Windows.DependencyObject,System.Object)"/> method.
/// </summary>
/// <param name="element">The container element.</param>
/// <param name="item">The item.</param>
protected override void ClearContainerForItemOverride(DependencyObject element, object item)
{
base.ClearContainerForItemOverride(element, item);
DataGridFacade.Instance.RemoveController(FooterCellController.FOOTER_PREFIX + element.GetHashCode());
}
示例6: ClearContainerForItemOverride
/// <summary>
/// Undoes the effects of the <see cref="ItemsControl.PrepareContainerForItemOverride(System.Windows.DependencyObject,System.Object)"/> method.
/// </summary>
/// <param name="element">The container element.</param>
/// <param name="item">The item.</param>
protected override void ClearContainerForItemOverride(DependencyObject element, object item)
{
base.ClearContainerForItemOverride(element, item);
DataGridFacade.Instance.RemoveController(element.GetHashCode().ToString());
}
示例7: ApplyTemplateContent
//+----------------------------------------------------------------------------------
//
// ApplyTemplateContent
//
// Instantiate the content of the template (either from FEFs or from Baml).
// This is done for every element to which this template is attached.
//
//+----------------------------------------------------------------------------------
#region InstantiateSubTree
//[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
internal static bool ApplyTemplateContent(
UncommonField<HybridDictionary[]> dataField,
DependencyObject container,
FrameworkElementFactory templateRoot,
int lastChildIndex,
HybridDictionary childIndexFromChildID,
FrameworkTemplate frameworkTemplate)
{
Debug.Assert(frameworkTemplate != null );
bool visualsCreated = false;
FrameworkElement feContainer = container as FrameworkElement;
// Is this a FEF-style template?
if (templateRoot != null)
{
// Yes, we'll instantiate from a FEF tree.
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseInstVisTreeBegin);
CheckForCircularReferencesInTemplateTree(container, frameworkTemplate );
// Container is considered ChildIndex '0' (Self), but,
// Container.ChildIndex isn't set
List<DependencyObject> affectedChildren = new List<DependencyObject>(lastChildIndex);
// Assign affectedChildren to container
TemplatedFeChildrenField.SetValue(container, affectedChildren);
// When building the template children chain, we keep a chain of
// nodes that don't need to be in the chain for property invalidation
// or lookup purposes. (And hence not assigned a TemplateChildIndex)
// We only need them in order to clean up their _templatedParent
// references (see FrameworkElement.ClearTemplateChain)
List<DependencyObject> noChildIndexChildren = null;
// Instantiate template
// Setup container's reference to first child in chain
// and add to tree
DependencyObject treeRoot = templateRoot.InstantiateTree(
dataField,
container,
container,
affectedChildren,
ref noChildIndexChildren,
ref frameworkTemplate.ResourceDependents);
Debug.Assert(treeRoot is FrameworkElement || treeRoot is FrameworkContentElement,
"Root node of tree must be a FrameworkElement or FrameworkContentElement. This should have been caught by set_VisualTree" );
// From childFirst to childLast is the chain of child nodes with
// childIndex. Append that chain with the chain of child nodes
// with no childIndex assigned.
if( noChildIndexChildren != null )
{
affectedChildren.AddRange(noChildIndexChildren);
}
visualsCreated = true;
if (feContainer != null && EventTrace.IsEnabled(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose))
{
string label = feContainer.Name;
if (label == null || label.Length == 0)
label = container.GetHashCode().ToString(System.Globalization.CultureInfo.InvariantCulture);
EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientParseInstVisTreeEnd, EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose,
String.Format(System.Globalization.CultureInfo.InvariantCulture, "Style.InstantiateSubTree for {0} {1}", container.GetType().Name, label));
}
}
// It's not a FEF-style template, is it a non-empty optimized one?
else if (frameworkTemplate != null && frameworkTemplate.HasXamlNodeContent)
{
// Yes, create from the optimized template content.
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseInstVisTreeBegin);
CheckForCircularReferencesInTemplateTree(container, frameworkTemplate );
// Container is considered ChildIndex '0' (Self), but,
// Container.ChildIndex isn't set
List<DependencyObject> affectedChildren = new List<DependencyObject>(lastChildIndex);
// Assign affectedChildren to container
//.........这里部分代码省略.........