public void Should_Register_With_Host_When_TemplatedParent_Set() { var host = new Mock<IContentPresenterHost>(); var target = new ContentPresenter(); target.SetValue(Control.TemplatedParentProperty, host.Object); host.Verify(x => x.RegisterContentPresenter(target)); }
public void Should_Set_Childs_Parent_To_Itself_Outside_Template() { var content = new Border(); var target = new ContentPresenter { Content = content }; target.UpdateChild(); Assert.Same(target, content.Parent); }
public void Setting_Content_Should_Make_Control_Appear_In_LogicalChildren() { var target = new ContentPresenter(); var child = new Control(); target.Content = child; target.ApplyTemplate(); Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList()); }
public void Clearing_Content_Should_Remove_From_LogicalChildren() { var target = new ContentPresenter(); var child = new Control(); target.Content = child; target.Content = null; Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList()); }
public void Setting_Content_To_String_Should_Create_TextBlock() { var target = new ContentPresenter(); target.Content = "Foo"; Assert.Null(target.Child); target.UpdateChild(); Assert.IsType<TextBlock>(target.Child); Assert.Equal("Foo", ((TextBlock)target.Child).Text); }
public void Setting_Content_To_Control_Should_Set_Child() { var target = new ContentPresenter(); var child = new Border(); target.Content = child; Assert.Null(target.Child); target.UpdateChild(); Assert.Equal(child, target.Child); }
public void Clearing_Content_Clear_Childs_Parent() { var target = new ContentPresenter(); var child = new Control(); target.Content = child; target.ApplyTemplate(); target.Content = null; target.ApplyTemplate(); Assert.Null(child.Parent); Assert.Null(child.GetLogicalParent()); }
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged() { var target = new ContentPresenter(); var child = new Control(); var called = false; ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = e.Action == NotifyCollectionChangedAction.Add; target.Content = child; target.ApplyTemplate(); Assert.True(called); }
public void Setting_Content_To_String_Should_Create_TextBlock() { var target = new ContentPresenter(); target.Content = "Foo"; // Child should not update until ApplyTemplate called. Assert.Null(target.Child); target.ApplyTemplate(); Assert.IsType<TextBlock>(target.Child); Assert.Equal("Foo", ((TextBlock)target.Child).Text); }
public void Setting_Content_To_Control_Should_Set_Child() { var target = new ContentPresenter(); var child = new Border(); target.Content = child; // Child should not update until ApplyTemplate called. Assert.Null(target.Child); target.ApplyTemplate(); Assert.Equal(child, target.Child); }
public void Adding_To_Logical_Tree_Should_Reevaluate_DataTemplates() { var target = new ContentPresenter { Content = "Foo", }; target.ApplyTemplate(); Assert.IsType<TextBlock>(target.Child); var root = new TestRoot { DataTemplates = new DataTemplates { new FuncDataTemplate<string>(x => new Decorator()), }, }; root.Child = target; target.ApplyTemplate(); Assert.IsType<Decorator>(target.Child); }
/// <inheritdoc/> protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { base.OnTemplateApplied(e); HeaderPresenter = e.NameScope.Find<ContentPresenter>("PART_HeaderPresenter"); }