コード例 #1
0
        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);
        }
コード例 #2
0
        void SetErrorMessage(string message)
        {
            ClearOutput();

            var textBlock = UIBuilder.Create <TextBlock>();

            textBlock.Text = message;

            Container.AddLogicalChild(textBlock);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
ファイル: ItemsControl.cs プロジェクト: modulexcite/Avalonia
        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);
                }
            }
        }