Orc.NuGetExplorer.FrameworkElementExtensions.UpdateItemSource C# (CSharp) Method

UpdateItemSource() public static method

public static UpdateItemSource ( this frameworkElement ) : void
frameworkElement this
return void
        public static void UpdateItemSource(this FrameworkElement frameworkElement)
        {
            Argument.IsNotNull(() => frameworkElement);

            var infos = frameworkElement.GetType().GetFields(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static);

            foreach (var field in infos.Where(x => x.FieldType == typeof (DependencyProperty)))
            {
                var dp = (DependencyProperty) field.GetValue(null);
                var bindingExpression = frameworkElement.GetBindingExpression(dp);
                if (bindingExpression == null)
                {
                    continue;
                }

                if (bindingExpression.ParentBinding.UpdateSourceTrigger == UpdateSourceTrigger.Explicit)
                {
                    bindingExpression.UpdateSource();
                }
            }

            var count = VisualTreeHelper.GetChildrenCount(frameworkElement);
            for (var i = 0; i < count; i++)
            {
                var child = VisualTreeHelper.GetChild(frameworkElement, i) as FrameworkElement;
                if (child != null)
                {
                    child.UpdateItemSource();
                }
            }
        }
        #endregion
FrameworkElementExtensions