本文整理汇总了C#中System.Windows.DependencyObject.GetLocalValueEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetLocalValueEnumerator方法的具体用法?C# DependencyObject.GetLocalValueEnumerator怎么用?C# DependencyObject.GetLocalValueEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetLocalValueEnumerator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
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);
}
}
示例2: InvalidateResourceReferences
/// <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);
}
}
}
示例3: ClearAllBindings
/// <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]);
}
}
示例4: SelectTemplate
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);
}
示例5: RemoveBindingExpressions
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);
}
}
}
示例6: EnumerateBindings
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;
}
}
}
示例7: ValidateBindings
// 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;
}
示例8: EndEdit
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);
}
}