Ejemplo n.º 1
0
        public void Nested_Templated_Control_Should_Not_Have_Template_Applied()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new ScrollViewer())
            };

            target.ApplyTemplate();

            var child = (ScrollViewer)target.GetVisualChildren().Single();

            Assert.Empty(child.GetVisualChildren());
        }
Ejemplo n.º 2
0
        public void Templated_Child_Should_Have_Parent_Set()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new Decorator())
            };

            target.ApplyTemplate();

            var child = (Decorator)target.GetVisualChildren().Single();

            Assert.Equal(target, child.Parent);
            Assert.Equal(target, child.GetLogicalParent());
        }
Ejemplo n.º 3
0
        public void Changing_Template_Should_Clear_Old_Templated_Childs_Parent()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate((_, __) => new Decorator())
            };

            target.ApplyTemplate();

            var child = (Decorator)target.GetVisualChildren().Single();

            target.Template = new FuncControlTemplate((_, __) => new Canvas());
            target.ApplyTemplate();

            Assert.Null(child.Parent);
        }
Ejemplo n.º 4
0
        public void Template_Result_Becomes_Visual_Child()
        {
            Control templateResult = new Control();

            var template = new ControlTemplate(_ =>
            {
                return(templateResult);
            });

            var target = new TemplatedControl
            {
                Template = template,
            };

            target.Measure(new Size(100, 100));
            var children = target.GetVisualChildren().ToList();

            CollectionAssert.AreEqual(new[] { templateResult }, children);
        }
Ejemplo n.º 5
0
        public void Templated_Child_Should_Have_ApplyTemplate_Called_With_Logical_Then_Visual_Parent()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new ApplyTemplateTracker())
            };

            target.ApplyTemplate();

            var child = (ApplyTemplateTracker)target.GetVisualChildren().Single();

            Assert.Equal(
                new[]
            {
                new Tuple <IVisual, ILogical>(null, target),
                new Tuple <IVisual, ILogical>(target, target),
            },
                child.Invocations);
        }
Ejemplo n.º 6
0
        public void Templated_Child_Should_Be_NameScope()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new Decorator
                {
                    Child = new Panel
                    {
                        Children = new Controls
                        {
                            new TextBlock(),
                            new Border(),
                        }
                    }
                }),
            };

            target.ApplyTemplate();

            Assert.NotNull(NameScope.GetNameScope((Control)target.GetVisualChildren().Single()));
        }