public void ResourceInheritanceTest() { object value; FrameworkElement root = new FrameworkElement(); root.Resources = new ResourceDictionary(); root.Resources.Add("key1", "value1"); Assert.IsTrue(root.TryGetResource("key1", out value)); Assert.AreEqual("value1", value); FrameworkElement child1 = new FrameworkElement(); root.AddVisualChild(child1); root.AddLogicalChild(child1); Assert.IsTrue(child1.TryGetResource("key1", out value)); Assert.AreEqual("value1", value); child1.Resources = new ResourceDictionary(); child1.Resources.Add("key1", "value2"); FrameworkElement child2 = new FrameworkElement(); child1.AddVisualChild(child2); Assert.IsTrue(child2.TryGetResource("key1", out value)); Assert.AreEqual("value2", value); root.AddLogicalChild(child2); Assert.IsTrue(child2.TryGetResource("key1", out value)); Assert.AreEqual("value1", value); }
void SetErrorMessage(string message) { ClearOutput(); var textBlock = UIBuilder.Create <TextBlock>(); textBlock.Text = message; Container.AddLogicalChild(textBlock); }
internal static void LoadComponent(FrameworkElement control, Element node, bool isDesignMode = false, Action <int, FrameworkElement> ElementCreatedAtLine = null, string xml = null) { var builder = new UIBuilder { _rootNode = node, DataContext = control, Caller = control, _isDesignMode = isDesignMode, XmlString = xml }; if (ElementCreatedAtLine != null) { builder.ElementCreatedAtLine += ElementCreatedAtLine; } var subControl = builder.BuildNode(builder._rootNode, control); var subControlAsFrameworkElement = subControl as FrameworkElement; if (subControlAsFrameworkElement == null) { throw new InvalidOperationException("ControlFirstItemMustBeHTMLElement"); } InitDOM(control); control.AddLogicalChild(subControlAsFrameworkElement); }
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)); }
private void SetLogicalParent(FrameworkElement parent, IList items) { foreach (DependencyObject o in items.OfType <DependencyObject>()) { FrameworkElement p = LogicalTreeHelper.GetParent(o) as FrameworkElement; if (p != null) { p.RemoveLogicalChild(o); } } if (parent != null) { foreach (object o in items) { parent.AddLogicalChild(o); } } }
private void SetLogicalParent(FrameworkElement parent, IList items) { foreach (DependencyObject o in items.OfType<DependencyObject>()) { FrameworkElement p = LogicalTreeHelper.GetParent(o) as FrameworkElement; if (p != null) { p.RemoveLogicalChild(o); } } if (parent != null) { foreach (object o in items) { parent.AddLogicalChild(o); } } }