示例#1
0
        public void Changing_Content_Should_Update_Presenter()
        {
            var target = new ContentControl();

            target.Template = this.GetTemplate();
            target.ApplyTemplate();

            target.Content = "Foo";
            target.Presenter.ApplyTemplate();
            Assert.Equal("Foo", ((TextBlock)target.Presenter.Child).Text);
            target.Content = "Bar";
            target.Presenter.ApplyTemplate();
            Assert.Equal("Bar", ((TextBlock)target.Presenter.Child).Text);
        }
示例#2
0
        public void ScrollViewer_In_Template_Sets_Child_TemplatedParent()
        {
            var target = new ContentControl
            {
                Template = ControlTemplate.Create<ContentControl>(this.CreateNestedTemplate),
                Content = "Foo",
            };

            target.ApplyTemplate();

            var presenter = target.GetVisualDescendents()
                .OfType<ContentPresenter>()
                .Single(x => x.Name == "this");

            Assert.Equal(target, presenter.TemplatedParent);
        }
示例#3
0
        public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var contentControl = new ContentControl();
            var child1 = new Control();
            var child2 = new Control();
            var called = false;

            contentControl.Template = this.GetTemplate();
            contentControl.Content = child1;
            contentControl.ApplyTemplate();

            ((ILogical)contentControl).LogicalChildren.CollectionChanged += (s, e) => called = true;

            contentControl.Content = child2;

            // Need to call ApplyTemplate on presenter for CollectionChanged to be called.
            var presenter = contentControl.GetTemplateChildren().Single(x => x.Name == "contentPresenter");
            presenter.ApplyTemplate();

            Assert.True(called);
        }
示例#4
0
        public void Templated_Children_Should_Be_Styled()
        {
            using (var ctx = this.RegisterServices())
            {
                var root = new TestRoot();
                var target = new ContentControl();
                var styler = new Mock<IStyler>();

                Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler));
                target.Content = "Foo";
                target.Template = this.GetTemplate();
                root.Content = target;

                target.ApplyTemplate();

                styler.Verify(x => x.ApplyStyles(It.IsAny<ContentControl>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<Border>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<ContentPresenter>()), Times.Once());
                styler.Verify(x => x.ApplyStyles(It.IsAny<TextBlock>()), Times.Once());
            }
        }
示例#5
0
        public void Setting_Content_To_String_Should_Set_Child_Controls_Parent()
        {
            var target = new ContentControl
            {
                Template = this.GetTemplate(),
            };

            target.Content = "Foo";
            target.ApplyTemplate();

            var child = target.Presenter.Child;

            Assert.Equal(child.Parent, target);
            Assert.Equal(((ILogical)child).LogicalParent, target);
        }
示例#6
0
        public void Setting_Content_To_String_Should_Make_TextBlock_Appear_In_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

            target.Template = this.GetTemplate();
            target.Content = "Foo";
            target.ApplyTemplate();

            var logical = (ILogical)target;
            Assert.Equal(1, logical.LogicalChildren.Count);
            Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
        }
示例#7
0
        public void Setting_Content_To_Control_Should_Make_Control_Appear_In_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
        }
示例#8
0
        public void Content_Should_Have_TemplatedParent_Set_To_Null()
        {
            var target = new ContentControl();
            var child = new Border();

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            Assert.Null(child.TemplatedParent);
        }
示例#9
0
        public void ContentPresenter_Should_Have_TemplatedParent_Set()
        {
            var target = new ContentControl();
            var child = new Border();

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            var contentPresenter = child.GetVisualParent<ContentPresenter>();
            Assert.Equal(target, contentPresenter.TemplatedParent);
        }
示例#10
0
        public void Clearing_Content_Should_Remove_From_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            target.Content = null;

            // Need to call ApplyTemplate on presenter for LogocalChildren to be updated.
            var presenter = target.GetTemplateChildren().Single(x => x.Name == "contentPresenter");
            presenter.ApplyTemplate();

            Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
        }
示例#11
0
        public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ContentControl();
            var child = new Control();
            var called = false;

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;

            target.Content = null;

            // Need to call ApplyTemplate on presenter for CollectionChanged to be called.
            var presenter = target.GetTemplateChildren().Single(x => x.Name == "contentPresenter");
            presenter.ApplyTemplate();

            Assert.True(called);
        }
示例#12
0
        public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ContentControl();
            var child = new Control();
            var called = false;

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
                called = e.Action == NotifyCollectionChangedAction.Add;

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            // Need to call ApplyTemplate on presenter for LogicalChildren to be updated.
            target.Presenter.ApplyTemplate();

            Assert.True(called);
        }
示例#13
0
        public void Clearing_Content_Should_Remove_From_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

            target.Template = this.GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

            target.Content = null;

            // Need to call ApplyTemplate on presenter for LogicalChildren to be updated.
            target.Presenter.ApplyTemplate();

            Assert.Empty(target.GetLogicalChildren());
        }