public void Control_Content_Should_Not_Be_NameScope() { var target = new ContentPresenter(); target.Content = new TextBlock(); Assert.Null(target.Child); target.UpdateChild(); Assert.IsType<TextBlock>(target.Child); Assert.Null(NameScope.GetNameScope((Control)target.Child)); }
public void DataTemplate_Created_Control_Should_Be_NameScope() { var target = new ContentPresenter(); target.Content = "Foo"; Assert.Null(target.Child); target.UpdateChild(); Assert.IsType<TextBlock>(target.Child); Assert.NotNull(NameScope.GetNameScope((Control)target.Child)); }
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 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 Should_Remove_Old_Child_From_LogicalChildren_On_ContentChanged_OutsideTemplate() { var target = new ContentPresenter { ContentTemplate = new FuncDataTemplate<string>(t => new ContentControl() { Content = t }, false) }; target.Content = "foo"; target.UpdateChild(); var foo = target.Child as ContentControl; Assert.NotNull(foo); var logicalChildren = target.GetLogicalChildren(); Assert.Equal(1, logicalChildren.Count()); target.Content = "bar"; target.UpdateChild(); Assert.Equal(null, foo.Parent); logicalChildren = target.GetLogicalChildren(); Assert.Equal(1, logicalChildren.Count()); Assert.NotEqual(foo, logicalChildren.First()); }
public void Should_Raise_DetachedFromLogicalTree_On_Detached_OutsideTemplate() { var target = new ContentPresenter { ContentTemplate = new FuncDataTemplate<string>(t => new ContentControl() { Content = t }, false) }; var parentMock = new Mock<Control>(); parentMock.As<IContentPresenterHost>(); parentMock.As<IStyleRoot>(); (target as ISetLogicalParent).SetParent(parentMock.Object); target.Content = "foo"; target.UpdateChild(); var foo = target.Child as ContentControl; bool foodetached = false; Assert.NotNull(foo); Assert.Equal("foo", foo.Content); foo.DetachedFromLogicalTree += delegate { foodetached = true; }; (target as ISetLogicalParent).SetParent(null); Assert.False((foo as IControl).IsAttachedToLogicalTree); Assert.True(foodetached); }
public void Tries_To_Recycle_DataTemplate() { var target = new ContentPresenter { DataTemplates = new DataTemplates { new FuncDataTemplate<string>(_ => new Border(), true), }, Content = "foo", }; target.UpdateChild(); var control = target.Child; Assert.IsType<Border>(control); target.Content = "bar"; target.UpdateChild(); Assert.Same(control, target.Child); }
public void Assigning_NonControl_To_Content_Should_Set_DataContext_On_UpdateChild() { var target = new ContentPresenter { Content = "foo", }; target.UpdateChild(); Assert.Equal("foo", target.DataContext); }
public void Adding_To_Logical_Tree_Should_Reevaluate_DataTemplates() { var target = new ContentPresenter { Content = "Foo", }; target.UpdateChild(); 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); }
public void Should_Add_Child_To_Own_LogicalChildren_Outside_Template() { var content = new Border(); var target = new ContentPresenter { Content = content }; target.UpdateChild(); var logicalChildren = target.GetLogicalChildren(); Assert.Equal(1, logicalChildren.Count()); Assert.Equal(content, logicalChildren.First()); }
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); }