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); }
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()); }
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); }