Esempio n. 1
0
        public void Templated_Children_Should_Have_TemplatedParent_Set()
        {
            var target = new TestTemplatedControl
            {
                Template = new FuncControlTemplate(_ =>
                {
                    return(new StackPanel
                    {
                        Children = new Controls
                        {
                            new TextBlock
                            {
                            }
                        }
                    });
                }),
            };

            target.ApplyTemplate();

            var panel     = target.GetTemplateChildren().OfType <StackPanel>().Single();
            var textBlock = target.GetTemplateChildren().OfType <TextBlock>().Single();

            Assert.Equal(target, panel.TemplatedParent);
            Assert.Equal(target, textBlock.TemplatedParent);
        }
Esempio n. 2
0
        public void Template_Should_Be_Instantated()
        {
            var target = new TestTemplatedControl
            {
                Template = new FuncControlTemplate(_ =>
                {
                    return(new StackPanel
                    {
                        Children = new Controls
                        {
                            new TextBlock
                            {
                            }
                        }
                    });
                }),
            };

            target.ApplyTemplate();

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

            Assert.IsType <StackPanel>(child);
            child = child.VisualChildren.Single();
            Assert.IsType <TextBlock>(child);
        }
Esempio n. 3
0
        public void Templated_Children_Should_Be_Styled()
        {
            using (Locator.Current.WithResolver())
            {
                var styler = new Mock <IStyler>();
                Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler));

                TestTemplatedControl target;

                var root = new TestRoot
                {
                    Child = target = new TestTemplatedControl
                    {
                        Template = new ControlTemplate(_ =>
                        {
                            return(new StackPanel
                            {
                                Children = new Controls
                                {
                                    new TextBlock
                                    {
                                    }
                                }
                            });
                        }),
                    }
                };

                target.ApplyTemplate();

                styler.Verify(x => x.ApplyStyles(It.IsAny <TestTemplatedControl>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny <StackPanel>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny <TextBlock>()), Times.Once());
            }
        }
Esempio n. 4
0
        public void OnTemplateApplied_Is_Called()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return(new Control());
                })
            };

            var children = ((IVisual)target).VisualChildren.ToArray();

            Assert.IsTrue(target.OnTemplateAppliedCalled);
        }
        public void OnTemplateApplied_Is_Called()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return new Control();
                })
            };

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

            Assert.True(target.OnTemplateAppliedCalled);
        }
Esempio n. 6
0
        public void OnTemplateApplied_Is_Called()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return(new Control());
                })
            };

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

            Assert.IsTrue(target.OnTemplateAppliedCalled);
        }
        public void GetTemplateChildren_Should_Not_Return_Nested_Template_Controls()
        {
            var target = new TestTemplatedControl();
            var border1 = new Border { Name = "border1", TemplatedParent = target };
            var inner = new TestTemplatedControl { Name = "inner", TemplatedParent = target };
            var border2 = new Border { Name = "border2", TemplatedParent = inner };
            var border3 = new Border { Name = "border3", TemplatedParent = inner };
            var border4 = new Border { Name = "border4", TemplatedParent = target };
            var border5 = new Border { Name = "border5", TemplatedParent = null };

            target.AddVisualChild(border1);
            border1.Child = inner;
            inner.AddVisualChild(border2);
            inner.AddVisualChild(border3);
            border3.Child = border4;
            border4.Child = border5;

            var result = target.GetTemplateChildren().Select(x => x.Name).ToArray();

            Assert.Equal(new[] { "border1", "inner", "border4" }, result);
        }
Esempio n. 8
0
        public void Presenter_Children_Should_Not_Have_TemplatedParent_Set()
        {
            var target = new TestTemplatedControl
            {
                Template = new FuncControlTemplate(_ =>
                {
                    return(new ContentPresenter
                    {
                        Content = new TextBlock
                        {
                        }
                    });
                }),
            };

            target.ApplyTemplate();

            var presenter = target.GetTemplateChildren().OfType <ContentPresenter>().Single();
            var textBlock = (TextBlock)presenter.Child;

            Assert.Equal(target, presenter.TemplatedParent);
            Assert.Null(textBlock.TemplatedParent);
        }
        public void Nested_Templated_Controls_Have_Correct_TemplatedParent()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return new ContentControl
                    {
                        Template = new ControlTemplate(parent =>
                        {
                            return new Border
                            {
                                Child = new ContentPresenter
                                {
                                    [~ContentPresenter.ContentProperty] = parent.GetObservable(ContentControl.ContentProperty),
                                }
                            };
                        }),
                        Content = new TextBlock
                        {
                        }
                    };
                }),
            };

            target.ApplyTemplate();

            var contentControl = target.GetTemplateChildren().OfType<ContentControl>().Single();
            var border = contentControl.GetTemplateChildren().OfType<Border>().Single();
            var presenter = contentControl.GetTemplateChildren().OfType<ContentPresenter>().Single();
            var textBlock = (TextBlock)presenter.Content;

            Assert.Equal(target, contentControl.TemplatedParent);
            Assert.Equal(contentControl, border.TemplatedParent);
            Assert.Equal(contentControl, presenter.TemplatedParent);
            Assert.Equal(target, textBlock.TemplatedParent);
        }
Esempio n. 10
0
        public void Nested_Templated_Controls_Have_Correct_TemplatedParent()
        {
            var target = new TestTemplatedControl
            {
                Template = new FuncControlTemplate(_ =>
                {
                    return(new ContentControl
                    {
                        Template = new FuncControlTemplate(parent =>
                        {
                            return new Border
                            {
                                Child = new ContentPresenter
                                {
                                    [~ContentPresenter.ContentProperty] = parent.GetObservable(ContentControl.ContentProperty),
                                }
                            };
                        }),
                        Content = new TextBlock
                        {
                        }
                    });
                }),
            };

            target.ApplyTemplate();

            var contentControl = target.GetTemplateChildren().OfType <ContentControl>().Single();
            var border         = contentControl.GetTemplateChildren().OfType <Border>().Single();
            var presenter      = contentControl.GetTemplateChildren().OfType <ContentPresenter>().Single();
            var textBlock      = (TextBlock)presenter.Content;

            Assert.Equal(target, contentControl.TemplatedParent);
            Assert.Equal(contentControl, border.TemplatedParent);
            Assert.Equal(contentControl, presenter.TemplatedParent);
            Assert.Equal(target, textBlock.TemplatedParent);
        }
Esempio n. 11
0
        public void Templated_Children_Should_Be_Styled()
        {
            using (PerspexLocator.EnterScope())
            {
                var styler = new Mock <IStyler>();

                PerspexLocator.CurrentMutable.Bind <IStyler>().ToConstant(styler.Object);

                TestTemplatedControl target;

                var root = new TestRoot
                {
                    Child = target = new TestTemplatedControl
                    {
                        Template = new FuncControlTemplate(_ =>
                        {
                            return(new StackPanel
                            {
                                Children = new Controls
                                {
                                    new TextBlock
                                    {
                                    }
                                }
                            });
                        }),
                    }
                };

                target.ApplyTemplate();

                styler.Verify(x => x.ApplyStyles(It.IsAny <TestTemplatedControl>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny <StackPanel>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny <TextBlock>()), Times.Once());
            }
        }
Esempio n. 12
0
        public void Presenter_Children_Should_Not_Have_TemplatedParent_Set()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return new ContentPresenter
                    {
                        Content =  new TextBlock
                        {
                        }
                    };
                }),
            };

            target.ApplyTemplate();

            var presenter = target.GetTemplateChildren().OfType<ContentPresenter>().Single();
            var textBlock = (TextBlock)presenter.Child;

            Assert.Equal(target, presenter.TemplatedParent);
            Assert.Null(textBlock.TemplatedParent);
        }
Esempio n. 13
0
        public void Template_Should_Be_Instantated()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return new StackPanel
                    {
                        Children = new Controls
                        {
                            new TextBlock
                            {
                            }
                        }
                    };
                }),
            };

            target.ApplyTemplate();

            var child = target.GetVisualChildren().Single();
            Assert.IsType<StackPanel>(child);
            child = child.VisualChildren.Single();
            Assert.IsType<TextBlock>(child);
        }
Esempio n. 14
0
        public void Templated_Children_Should_Have_TemplatedParent_Set()
        {
            var target = new TestTemplatedControl
            {
                Template = new ControlTemplate(_ =>
                {
                    return new StackPanel
                    {
                        Children = new Controls
                        {
                            new TextBlock
                            {
                            }
                        }
                    };
                }),
            };

            target.ApplyTemplate();

            var panel = target.GetTemplateChildren().OfType<StackPanel>().Single();
            var textBlock = target.GetTemplateChildren().OfType<TextBlock>().Single();

            Assert.Equal(target, panel.TemplatedParent);
            Assert.Equal(target, textBlock.TemplatedParent);
        }
Esempio n. 15
0
        public void Templated_Children_Should_Be_Styled()
        {
            using (Locator.Current.WithResolver())
            {
                var styler = new Mock<IStyler>();
                Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler));

                TestTemplatedControl target;

                var root = new TestRoot
                {
                    Child = (target = new TestTemplatedControl
                    {
                        Template = new ControlTemplate(_ =>
                        {
                            return new StackPanel
                            {
                                Children = new Controls
                            {
                                new TextBlock
                                {
                                }
                            }
                            };
                        }),
                    })
                };

                target.ApplyTemplate();

                styler.Verify(x => x.ApplyStyles(It.IsAny<TestTemplatedControl>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<StackPanel>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<TextBlock>()), Times.Once());
            }
        }
        public void Templated_Children_Should_Be_Styled()
        {
            using (PerspexLocator.EnterScope())
            {
                var styler = new Mock<IStyler>();

                PerspexLocator.CurrentMutable.Bind<IStyler>().ToConstant(styler.Object);

                TestTemplatedControl target;

                var root = new TestRoot
                {
                    Child = target = new TestTemplatedControl
                    {
                        Template = new FuncControlTemplate(_ =>
                        {
                            return new StackPanel
                            {
                                Children = new Controls
                            {
                                new TextBlock
                                {
                                }
                            }
                            };
                        }),
                    }
                };

                target.ApplyTemplate();

                styler.Verify(x => x.ApplyStyles(It.IsAny<TestTemplatedControl>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<StackPanel>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<TextBlock>()), Times.Once());
            }
        }