Esempio n. 1
1
        public void ApplyTemplate_Should_Create_Visual_Children()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new Decorator
                {
                    Child = new Panel
                    {
                        Children = new Controls
                        {
                            new TextBlock(),
                            new Border(),
                        }
                    }
                }),
            };

            target.ApplyTemplate();

            var types = target.GetVisualDescendents().Select(x => x.GetType()).ToList();

            Assert.Equal(
                new[]
                {
                    typeof(Decorator),
                    typeof(Panel),
                    typeof(TextBlock),
                    typeof(Border)
                },
                types);
            Assert.Empty(target.GetLogicalChildren());
        }
Esempio n. 2
0
        public void Template_Doesnt_Get_Executed_On_Set()
        {
            bool executed = false;

            var template = new FuncControlTemplate(_ =>
            {
                executed = true;
                return new Control();
            });

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

            Assert.False(executed);
        }
Esempio n. 3
0
        public void Template_Gets_Executed_On_Measure()
        {
            bool executed = false;

            var template = new FuncControlTemplate(_ =>
            {
                executed = true;
                return new Control();
            });

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

            target.Measure(new Size(100, 100));

            Assert.True(executed);
        }
Esempio n. 4
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()));
        }
Esempio n. 5
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());
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
        public void Templated_Children_Should_Have_TemplatedParent_Set()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new Decorator
                {
                    Child = new Panel
                    {
                        Children = new Controls
                        {
                            new TextBlock(),
                            new Border(),
                        }
                    }
                }),
            };

            target.ApplyTemplate();

            var templatedParents = target.GetVisualDescendents()
                .OfType<IControl>()
                .Select(x => x.TemplatedParent)
                .ToList();

            Assert.Equal(4, templatedParents.Count);
            Assert.True(templatedParents.All(x => x == target));
        }