当前位置: 首页>>代码示例>>C#>>正文


C# DependencyObject.GetChildren方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:modulexcite,项目名称:SoftFluent.Windows,代码行数:7,代码来源:PropertyGrid.xaml.cs

示例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);
                }
            }
        }
开发者ID:ktei,项目名称:RyarcWorkSL4,代码行数:53,代码来源:RefreshBindingScope.cs


注:本文中的System.Windows.DependencyObject.GetChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。