本文整理汇总了C#中System.Windows.DependencyObject.GetChildren方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetChildren方法的具体用法?C# DependencyObject.GetChildren怎么用?C# DependencyObject.GetChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetChildren方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshSelectedObject
public static void RefreshSelectedObject(DependencyObject editor)
{
foreach (PropertyGrid grid in editor.GetChildren<PropertyGrid>())
{
grid.RefreshSelectedObject();
}
}
示例2: RefreshBinding
/// <summary>
/// Recursively force each bound property to refresh it's binding
/// </summary>
/// <param name="dependencyObject">UI control</param>
/// <remarks>This "walks" the visual tree to find controls that have a bound property
/// and it then refreshes the binding, which forces any validation rule to be re-run.
/// If the control does not have a bound property, the children controls are checked.
/// This handles situations when text boxes or other validated controls are within
/// an <c>ItemsControl</c>, <c>ListBox</c>, <c>DataGrid</c>, <c>Grid</c>
/// <c>StackPanel</c>, or <c>Canvas</c>. Child controls for <c>Button</c>,
/// <c>HyperlinkButton</c>, and <c>ValidationSummary</c> are ignored, since they shouldn't
/// have bound children with validation rules.</remarks>
private static void RefreshBinding(DependencyObject dependencyObject)
{
Debug.WriteLine(dependencyObject.GetType());
// stop if we've reached a validation summary
var validationSummary = dependencyObject as ValidationSummary;
if (validationSummary != null) return;
// don't do buttons - should be nothing to validate
var button = dependencyObject as Button;
if (button != null) return;
// don't do hyperlink buttons - should be nothing to validate
var hyperLinkButton = dependencyObject as HyperlinkButton;
if (hyperLinkButton != null) return;
foreach (var item in dependencyObject.GetChildren())
{
var found = false;
// get bound property (use list from BindingHelper, so we don't repeat it in this class)
DependencyProperty boundProperty;
if (BoundProperties.TryGetValue(item.GetType(), out boundProperty))
{
// get BindingExpression and, if exists, force it to refresh
var be = ((FrameworkElement)item).GetBindingExpression(boundProperty);
if (be != null) be.UpdateSource();
// binding refreshed, so don't look for children
found = true;
Debug.WriteLine(string.Format("{0} binding refreshed ({1}).", item, item.GetValue(boundProperty)));
}
// get children recursively if bound property has not already been found
if (!found)
{
RefreshBinding(item);
}
}
}