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

            target.ApplyTemplate();

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

            Assert.Equal(
                new[]
            {
                typeof(Decorator),
                typeof(Panel),
                typeof(TextBlock),
                typeof(Border)
            },
                types);
            Assert.Empty(target.GetLogicalChildren());
        }
Ejemplo n.º 2
0
        public void Templated_Children_Should_Have_TemplatedParent_Set()
        {
            var target = new TemplatedControl
            {
                Template = new FuncControlTemplate(_ => new Decorator
                {
                    Child = new Panel
                    {
                        Children =
                        {
                            new TextBlock(),
                            new Border(),
                        }
                    }
                }),
            };

            target.ApplyTemplate();

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

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