Exemplo n.º 1
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);
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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);
        }