当前位置: 首页>>代码示例>>C#>>正文


C# ContentControl.ApplyTemplate方法代码示例

本文整理汇总了C#中ContentControl.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# ContentControl.ApplyTemplate方法的具体用法?C# ContentControl.ApplyTemplate怎么用?C# ContentControl.ApplyTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentControl的用法示例。


在下文中一共展示了ContentControl.ApplyTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Content_Should_Have_TemplatedParent_Set_To_Null

        public void Content_Should_Have_TemplatedParent_Set_To_Null()
        {
            var target = new ContentControl();
            var child = new Border();

            target.Template = GetTemplate();
            target.Content = child;
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

            Assert.Null(child.TemplatedParent);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:12,代码来源:ContentControlTests.cs

示例2: ContentPresenter_Should_Have_TemplatedParent_Set

        public void ContentPresenter_Should_Have_TemplatedParent_Set()
        {
            var target = new ContentControl();
            var child = new Border();

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

            var contentPresenter = child.GetVisualParent<ContentPresenter>();
            Assert.Equal(target, contentPresenter.TemplatedParent);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:12,代码来源:ContentControlTests.cs

示例3: Template_Should_Be_Instantiated

        public void Template_Should_Be_Instantiated()
        {
            var target = new ContentControl();
            target.Content = "Foo";
            target.Template = GetTemplate();
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

            var child = ((IVisual)target).VisualChildren.Single();
            Assert.IsType<Border>(child);
            child = child.VisualChildren.Single();
            Assert.IsType<ContentPresenter>(child);
            child = child.VisualChildren.Single();
            Assert.IsType<TextBlock>(child);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:15,代码来源:ContentControlTests.cs

示例4: Changing_Content_Should_Update_Presenter

        public void Changing_Content_Should_Update_Presenter()
        {
            var target = new ContentControl();

            target.Template = GetTemplate();
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

            target.Content = "Foo";
            ((ContentPresenter)target.Presenter).UpdateChild();
            Assert.Equal("Foo", ((TextBlock)target.Presenter.Child).Text);
            target.Content = "Bar";
            ((ContentPresenter)target.Presenter).UpdateChild();
            Assert.Equal("Bar", ((TextBlock)target.Presenter.Child).Text);
        }
开发者ID:randydotnet,项目名称:Perspex,代码行数:15,代码来源:ContentControlTests.cs

示例5: Templated_Children_Should_Be_Styled

        public void Templated_Children_Should_Be_Styled()
        {
            var root = new TestRoot();
            var target = new ContentControl();
            var styler = new Mock<IStyler>();

            AvaloniaLocator.CurrentMutable.Bind<IStyler>().ToConstant(styler.Object);
            target.Content = "Foo";
            target.Template = GetTemplate();
            root.Child = 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());
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:18,代码来源:ContentControlTests.cs

示例6: Changing_Content_Should_Fire_LogicalChildren_CollectionChanged

        public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ContentControl();
            var child1 = new Control();
            var child2 = new Control();
            var called = false;

            target.Template = GetTemplate();
            target.Content = child1;
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

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

            target.Content = child2;
            target.Presenter.ApplyTemplate();

            Assert.True(called);
        }
开发者ID:randydotnet,项目名称:Perspex,代码行数:19,代码来源:ContentControlTests.cs

示例7: Changing_Content_Should_Fire_LogicalChildren_CollectionChanged

        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 = 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.
            contentControl.Presenter.ApplyTemplate();

            Assert.True(called);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:20,代码来源:ContentControlTests.cs

示例8: Setting_Content_Should_Fire_LogicalChildren_CollectionChanged

        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 = GetTemplate();
            target.Content = child;
            target.ApplyTemplate();

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

            Assert.True(called);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:18,代码来源:ContentControlTests.cs

示例9: Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged

        public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ContentControl();
            var child = new Control();
            var called = false;

            target.Template = 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.
            target.Presenter.ApplyTemplate();

            Assert.True(called);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:19,代码来源:ContentControlTests.cs

示例10: Setting_Content_To_String_Should_Make_TextBlock_Appear_In_LogicalChildren

        public void Setting_Content_To_String_Should_Make_TextBlock_Appear_In_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

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

            var logical = (ILogical)target;
            Assert.Equal(1, logical.LogicalChildren.Count);
            Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:13,代码来源:ContentControlTests.cs

示例11: Clearing_Content_Should_Remove_From_LogicalChildren

        public void Clearing_Content_Should_Remove_From_LogicalChildren()
        {
            var target = new ContentControl();
            var child = new Control();

            target.Template = 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());
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:16,代码来源:ContentControlTests.cs

示例12: Control_Content_Should_Be_Logical_Child_After_ApplyTemplate

        public void Control_Content_Should_Be_Logical_Child_After_ApplyTemplate()
        {
            var target = new ContentControl
            {
                Template = GetTemplate(),
            };

            var child = new Control();
            target.Content = child;
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

            Assert.Equal(child.Parent, target);
            Assert.Equal(child.GetLogicalParent(), target);
            Assert.Equal(new[] { child }, target.GetLogicalChildren());
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:16,代码来源:ContentControlTests.cs

示例13: Nested_TemplatedControls_Should_Register_With_Correct_NameScope

        public void Nested_TemplatedControls_Should_Register_With_Correct_NameScope()
        {
            var target = new ContentControl
            {
                Template = new FuncControlTemplate<ContentControl>(ScrollingContentControlTemplate),
                Content = "foo"
            };

            var root = new TestRoot { Child = target };
            target.ApplyTemplate();

            var border = target.GetVisualChildren().FirstOrDefault();
            Assert.IsType<Border>(border);

            var scrollViewer = border.GetVisualChildren().FirstOrDefault();
            Assert.IsType<ScrollViewer>(scrollViewer);
            ((ScrollViewer)scrollViewer).ApplyTemplate();

            var scrollContentPresenter = scrollViewer.GetVisualChildren().FirstOrDefault();
            Assert.IsType<ScrollContentPresenter>(scrollContentPresenter);
            ((ContentPresenter)scrollContentPresenter).UpdateChild();

            var contentPresenter = scrollContentPresenter.GetVisualChildren().FirstOrDefault();
            Assert.IsType<ContentPresenter>(contentPresenter);

            var borderNs = NameScope.GetNameScope((Control)border);
            var scrollContentPresenterNs = NameScope.GetNameScope((Control)scrollContentPresenter);

            Assert.NotNull(borderNs);
            Assert.Same(scrollViewer, borderNs.Find("ScrollViewer"));
            Assert.Same(contentPresenter, borderNs.Find("PART_ContentPresenter"));
            Assert.Same(scrollContentPresenter, scrollContentPresenterNs.Find("PART_ContentPresenter"));
        }
开发者ID:akrisiun,项目名称:Avalonia,代码行数:33,代码来源:TemplatedControlTests.cs

示例14: Should_Use_ContentTemplate_To_Create_Control

        public void Should_Use_ContentTemplate_To_Create_Control()
        {
            var target = new ContentControl
            {
                Template = GetTemplate(),
                ContentTemplate = new FuncDataTemplate<string>(_ => new Canvas()),
            };

            target.Content = "Foo";
            target.ApplyTemplate();
            ((ContentPresenter)target.Presenter).UpdateChild();

            var child = target.Presenter.Child;

            Assert.IsType<Canvas>(child);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:16,代码来源:ContentControlTests.cs

示例15: DataContext_Should_Be_Set_For_Templated_Data

        public void DataContext_Should_Be_Set_For_Templated_Data()
        {
            var target = new ContentControl();

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

            Assert.Equal("Foo", target.Presenter.Child.DataContext);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:10,代码来源:ContentControlTests.cs


注:本文中的ContentControl.ApplyTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。