GetLocalValueEnumerator() private method

private GetLocalValueEnumerator ( ) : System.Windows.LocalValueEnumerator
return System.Windows.LocalValueEnumerator
Ejemplo n.º 1
0
        // Token: 0x06000C6A RID: 3178 RVA: 0x0002E850 File Offset: 0x0002CA50
        private static void InvalidateResourceReferences(DependencyObject d, ResourcesChangeInfo info)
        {
            LocalValueEnumerator localValueEnumerator = d.GetLocalValueEnumerator();
            int count = localValueEnumerator.Count;

            if (count > 0)
            {
                ResourceReferenceExpression[] array = new ResourceReferenceExpression[count];
                int num = 0;
                while (localValueEnumerator.MoveNext())
                {
                    LocalValueEntry             localValueEntry             = localValueEnumerator.Current;
                    ResourceReferenceExpression resourceReferenceExpression = localValueEntry.Value as ResourceReferenceExpression;
                    if (resourceReferenceExpression != null && info.Contains(resourceReferenceExpression.ResourceKey, false))
                    {
                        array[num] = resourceReferenceExpression;
                        num++;
                    }
                }
                ResourcesChangedEventArgs e = new ResourcesChangedEventArgs(info);
                for (int i = 0; i < num; i++)
                {
                    array[i].InvalidateExpressionValue(d, e);
                }
            }
        }
Ejemplo n.º 2
0
        private static void Clone(DependencyObject from, DependencyObject to)
        {
            var localValueEnumerator = from.GetLocalValueEnumerator();
            while (localValueEnumerator.MoveNext())
            {
                if (localValueEnumerator.Current.Property.ReadOnly ||
                    localValueEnumerator.Current.Value is FrameworkElement) continue;

                if (!(localValueEnumerator.Current.Value is BindingExpressionBase))
                    to.SetCurrentValue(localValueEnumerator.Current.Property, localValueEnumerator.Current.Value);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Invalidates all properties that reference a resource. 
        ///     NOTE: The return value for this method indicates whether or not a ResourceReference 
        ///     property was found on the given object. This is to take care of the special case when
        ///     programmatically changing a ResourceReference property value does not reflect on the 
        ///     bit stored on FrameworkElement or FrameworkContentElement that indicates whether
        ///     the current instance has ResourceReference values set on it. This current operation
        ///     is a point of synchronization for this flag.
        /// </summary> 
        /// <remarks>
        ///     This methods is called when one of the following operations occurred. 
        ///     1) A tree change 
        ///     2) A resource dictionary change
        ///     3) A modification to a single entry in a dictionary 
        /// </remarks>
        private static void InvalidateResourceReferences(
            DependencyObject    d,
            ResourcesChangeInfo info) 
        {
            Debug.Assert(d != null, "Must have non-null current node"); 
 
            // Find properties that have resource reference value
            LocalValueEnumerator localValues = d.GetLocalValueEnumerator(); 
            int localValuesCount = localValues.Count;

            if (localValuesCount > 0)
            { 
                // Resource reference invalidation involves two passes - first to
                // pick out what we need to invalidate, and the second to do the 
                // actual invalidation.  This is needed because LocalValueEnumerator 
                // will halt if any local values have changed, which can happen
                // depending on what people are doing in their OnPropertyChanged 
                // callback.

                // The following array is used to track the ResourceReferenceExpressions that we find
                ResourceReferenceExpression[] resources = new ResourceReferenceExpression[localValuesCount]; 
                int invalidationCount = 0;
 
                // Pass #1 - find what needs invalidation 
                while (localValues.MoveNext())
                { 
                    // Is this a resource reference?
                    ResourceReferenceExpression resource = localValues.Current.Value as ResourceReferenceExpression;
                    if (resource != null)
                    { 
                        // Record this property if it is referring
                        // to a resource that is being changed 
                        if (info.Contains(resource.ResourceKey, false /*isImplicitStyleKey*/)) 
                        {
                            resources[invalidationCount]  = resource; 
                            invalidationCount++;
                        }
                    }
                } 

                ResourcesChangedEventArgs args = new ResourcesChangedEventArgs(info); 
 
                // Pass #2 - actually make the invalidation calls, now that we're
                // outside the LocalValueEnumerator. 
                for (int i = 0; i < invalidationCount; i++)
                {
                    // Let the resource reference throw away its cache
                    // and invalidate the property in which it's held 
                    // re-evaluate expression
                    resources[i].InvalidateExpressionValue(d, args); 
                } 
            }
        } 
Ejemplo n.º 4
0
        /// <summary>
        /// Remove all data Binding (if any) from a DependencyObject. 
        /// </summary> 
        /// <param name="target">object from which to remove bindings</param>
        /// <exception cref="ArgumentNullException"> DependencyObject target cannot be null </exception> 
        public static void ClearAllBindings(DependencyObject target)
        {
            if (target == null)
                throw new ArgumentNullException("target"); 
//            target.VerifyAccess();
 
            LocalValueEnumerator lve = target.GetLocalValueEnumerator(); 

            // Batch properties that have BindingExpressions since clearing 
            // during a local value enumeration is illegal
            ArrayList batch = new ArrayList(8);

            while (lve.MoveNext()) 
            {
                LocalValueEntry entry = lve.Current; 
                if (IsDataBound(target, entry.Property)) 
                {
                    batch.Add(entry.Property); 
                }
            }

            // Clear all properties that are storing BindingExpressions 
            for (int i = 0; i < batch.Count; i++)
            { 
                target.ClearValue((DependencyProperty)batch[i]); 
            }
        } 
 public override DataTemplate SelectTemplate(object item, DependencyObject container)
 {
     if(item is InteriorProduct)
     {
         var enumerator = container.GetLocalValueEnumerator();
         enumerator.MoveNext();
         enumerator.MoveNext();
         enumerator.MoveNext();
         enumerator.MoveNext();
         return enumerator.Current.Value as DataTemplate;
     }
     return base.SelectTemplate(item, container);
 }
        private void RemoveBindingExpressions(BindingGroup bindingGroup, DependencyObject element)
        {
            // Walk the logical tree  looking for BindingBindingExpressions.
            // If it is found in the BindingGroup's BindingExpression list we will remove it.
            // We only search the logical tree for perf reasons, so some visual children could be skipped.  This 
            // should be ok for all the stock columns, and will be something that a custom column would need to be
            // aware of.
            if (element != null)
            {
                var bindingExpressions = bindingGroup.BindingExpressions;
                var localValueEnumerator = element.GetLocalValueEnumerator();
                while (localValueEnumerator.MoveNext())
                {
                    var bindingExpression = localValueEnumerator.Current.Value as BindingExpression;
                    if (bindingExpression != null)
                    {
                        for (int i = 0; i < bindingExpressions.Count; i++)
                        {
                            if (object.ReferenceEquals(bindingExpression, bindingExpressions[i]))
                            {
                                bindingExpressions.RemoveAt(i--);
                            }
                        }
                    }
                }

                // Recursively remove BindingExpressions from child elements.
                foreach (object child in LogicalTreeHelper.GetChildren(element))
                {
                    RemoveBindingExpressions(bindingGroup, child as DependencyObject);
                }
            }
        }
Ejemplo n.º 7
0
        public static IEnumerable<Binding> EnumerateBindings(DependencyObject element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            LocalValueEnumerator lve = element.GetLocalValueEnumerator();

            while (lve.MoveNext())
            {
                LocalValueEntry entry = lve.Current;

                if (BindingOperations.IsDataBound(element, entry.Property))
                {
                    Binding binding = (entry.Value as BindingExpression).ParentBinding;
                    yield return binding;
                }
            }
        }
Ejemplo n.º 8
0
        // This is here 'til future versions of WPF provide this functionality
        public static bool ValidateBindings(DependencyObject parent)
        {
            // Validate all the bindings on the parent
            bool valid = true;
            LocalValueEnumerator localValues = parent.GetLocalValueEnumerator();
            while (localValues.MoveNext())
            {
                LocalValueEntry entry = localValues.Current;
                if (BindingOperations.IsDataBound(parent, entry.Property))
                {
                    Binding binding = BindingOperations.GetBinding(parent, entry.Property);
                    foreach (ValidationRule rule in binding.ValidationRules)
                    {
                        // TODO: where to get correct culture info?
                        ValidationResult result = rule.Validate(parent.GetValue(entry.Property), null);
                        if (!result.IsValid)
                        {
                            BindingExpression expression = BindingOperations.GetBindingExpression(parent, entry.Property);
                            Validation.MarkInvalid(expression, new ValidationError(rule, expression, result.ErrorContent, null));
                            valid = false;
                        }
                    }
                }
            }

            // Validate all the bindings on the children
            for (int i = 0; i != VisualTreeHelper.GetChildrenCount(parent); ++i)
            {
                DependencyObject child = VisualTreeHelper.GetChild(parent, i);
                if (!ValidateBindings(child)) { valid = false; }
            }

            return valid;
        }
        private void EndEdit(DependencyObject parent)
        {
            LocalValueEnumerator localValues = parent.GetLocalValueEnumerator();
            while (localValues.MoveNext())
            {
                LocalValueEntry entry = localValues.Current;
                if (BindingOperations.IsDataBound(parent, entry.Property))
                {
                    BindingExpression binding = BindingOperations.GetBindingExpression(parent, entry.Property);
                    if (binding != null)
                    {
                        binding.UpdateSource();
                    }
                }
                
            }

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(parent, i);
                this.EndEdit(child);                
            }
        }