protected override void CopyCore(Freezable sourceFreezable) { base.CopyCore(sourceFreezable); sourceFreezable.SetValue(ByProperty, GetValue(ByProperty)); sourceFreezable.SetValue(FromProperty, GetValue(FromProperty)); sourceFreezable.SetValue(ToProperty, GetValue(ToProperty)); }
public void ContainingNameScopeTest() { FrameworkElement logicalParent = new FrameworkElement(); FrameworkElement visualParent = new FrameworkElement(); FrameworkElement child = new FrameworkElement(); NameScope logicalNameScope = new NameScope(); NameScope.SetNameScope(logicalParent, logicalNameScope); NameScope visualNameScope = new NameScope(); NameScope.SetNameScope(visualParent, visualNameScope); Freezable value = new Freezable(); Freezable subValue = new Freezable(); // visual / context tree: logicalParent -> visualParent -> child -> value -> subValue logicalParent.AddVisualChild(visualParent); visualParent.AddVisualChild(child); child.SetValue(ValueProperty, value); value.SetValue(ValueProperty, subValue); // logical tree: logicalParent -> child logicalParent.AddLogicalChild(child); Assert.AreEqual(logicalNameScope, NameScope.GetContainingNameScope(subValue)); }
public void ContextElementParentTest() { FrameworkElement root = new FrameworkElement(); FrameworkElement child = new FrameworkElement(); Freezable value = new Freezable(); Freezable subValue = new Freezable(); value.SetValue(ValueProperty, subValue); child.SetValue(ValueProperty, value); root.AddVisualChild(child); Assert.AreEqual(value, ((IContextElement)subValue).ContextParent); Assert.AreEqual(child, ((IContextElement)value).ContextParent); Assert.AreEqual(root, ((IContextElement)child).ContextParent); }
private static void TryFreeze(Freezable freezable) { var bindingProperty = GetBindingProperty(freezable); if (bindingProperty != null) { var bindingExpression = BindingOperations.GetBindingExpression(freezable, bindingProperty); if (bindingExpression == null) { freezable.Changed += OnFreezableChanged; return; } bindingExpression.UpdateTarget(); freezable.SetValue(bindingProperty, freezable.GetValue(bindingProperty)); BindingOperations.ClearAllBindings(freezable); freezable.Freeze(); } }