本文整理汇总了C#中System.Windows.DependencyObject.GetVisualChildren方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetVisualChildren方法的具体用法?C# DependencyObject.GetVisualChildren怎么用?C# DependencyObject.GetVisualChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetVisualChildren方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindControl
private DependencyObject FindControl(string id, DependencyObject currentParent)
{
var currChildren = currentParent.GetVisualChildren();
foreach (var item in currChildren)
{
if (item.GetValue(NameProperty).ToString().Equals(id))
return item;
var childItem = FindControl(id, item);
if (childItem != null)
return childItem;
}
return null;
}
示例2: FindLogicalNode
/// <summary>
/// Finds a logical node in the tree of the specified <see cref="DependencyObject"/>.
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <param name="name">The name of the control to find.</param>
/// <returns>Child as <see cref="DependencyObject"/> or <c>null</c> if the child cannot be found.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="dependencyObject"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">The <paramref name="name"/> is <c>null</c> or whitespace.</exception>
public static DependencyObject FindLogicalNode(DependencyObject dependencyObject, string name)
{
Argument.IsNotNull("dependencyObject", dependencyObject);
Argument.IsNotNullOrWhitespace("name", name);
// Check if the object is the node itself
if (IsElementWithName(dependencyObject, name))
{
return dependencyObject;
}
// Search all child nodes
var children = new List<DependencyObject>(dependencyObject.GetVisualChildren());
foreach (DependencyObject child in children)
{
if (IsElementWithName(child, name))
{
return child;
}
}
// Since we didn't find anything, check the childs of all childs
return children.Select(child => FindLogicalNode(child, name)).FirstOrDefault(foundChild => foundChild != null);
}
示例3: HasStringInSomePropertyOfItselfOrChildren
private bool HasStringInSomePropertyOfItselfOrChildren(DependencyObject node, string value)
{
foreach (var property in node.GetType().GetProperties())
{
if (property.CanRead && property.GetValue(node, null) as string == value)
{
return true;
}
}
foreach (var child in node.GetVisualChildren())
{
if (HasStringInSomePropertyOfItselfOrChildren(child, value))
{
return true;
}
}
return false;
}
示例4: GetStringsFromPropertiesOfItselfAndChildren
private string GetStringsFromPropertiesOfItselfAndChildren(DependencyObject node, string currentStrings)
{
foreach (var property in node.GetType().GetProperties())
{
if (property.CanRead)
{
currentStrings += "|" + property.GetValue(node, null);
}
}
foreach (var child in node.GetVisualChildren())
{
currentStrings = GetStringsFromPropertiesOfItselfAndChildren(child, currentStrings);
}
return currentStrings;
}
示例5: FindChildrenByType
private void FindChildrenByType(DependencyObject parent, Type type, ICollection<DependencyObject> children)
{
if (parent.GetType() == type)
{
children.Add(parent);
}
foreach (var child in parent.GetVisualChildren())
{
FindChildrenByType(child, type, children);
}
}
示例6: Describe
private string Describe(DependencyObject node, string identation)
{
var description = identation == string.Empty ? "" : identation.Substring(0, identation.Length - 1) + "-";
description += node;
description += !string.IsNullOrEmpty(node.GetValue(NameProperty).ToString())
? " - " + node.GetValue(NameProperty) : "";
if (node.GetType() == typeof(TextBlock))
{
description += " - " + ((TextBlock)node).Text;
}
description += "\n";
foreach (var child in node.GetVisualChildren())
{
description += Describe(child, identation + "| ");
}
return description;
}
示例7: GetChildren
protected override IEnumerable<DependencyObject> GetChildren(DependencyObject dependencyObject)
{
return dependencyObject.GetVisualChildren ();
}