Пример #1
0
        internal static bool ValidateWithoutUpdate(FrameworkElement element)
        {
            bool         result       = true;
            BindingGroup bindingGroup = element.BindingGroup;
            DataGridCell cell         = (element != null) ? element.Parent as DataGridCell : null;

            if (bindingGroup != null && cell != null)
            {
                Collection <BindingExpressionBase> expressions            = bindingGroup.BindingExpressions;
                BindingExpressionBase[]            bindingExpressionsCopy = new BindingExpressionBase[expressions.Count];
                expressions.CopyTo(bindingExpressionsCopy, 0);

                for (int i = 0; i < bindingExpressionsCopy.Length; i++)
                {
                    // Check the binding's target element - it might have been GC'd
                    // (this can happen when column-virtualization is enabled, see Dev11 131232).
                    // If so, fetching TargetElement will detach the binding and remove it
                    // from the binding group's collection.  This side-effect is why we
                    // loop through a copy of the original collection, and don't rely
                    // on i to be a valid index into the original collection.
                    BindingExpressionBase beb           = bindingExpressionsCopy[i];
                    DependencyObject      targetElement = beb.TargetElement;
                    if (targetElement != null &&
                        VisualTreeHelper.IsAncestorOf(cell, targetElement, typeof(DataGridCell)))
                    {
                        result = beb.ValidateWithoutUpdate() && result;
                    }
                }
            }

            return(result);
        }