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


C# ItemsControl.ApplyTemplate方法代码示例

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


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

示例1: Panel_Should_Have_TemplatedParent_Set_To_ItemsControl

        public void Panel_Should_Have_TemplatedParent_Set_To_ItemsControl()
        {
            var target = new ItemsControl();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();

            Assert.Equal(target, target.Presenter.Panel.TemplatedParent);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:10,代码来源:ItemsControlTests.cs

示例2: Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren

        public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren()
        {
            var target = new ItemsControl();
            var child = new Control();

            target.Template = GetTemplate();
            target.Items = new[] { child };
            target.ApplyTemplate();

            Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
        }
开发者ID:g4idrijs,项目名称:Perspex,代码行数:11,代码来源:ItemsControlTests.cs

示例3: Item_Should_Have_TemplatedParent_Set_To_Null

        public void Item_Should_Have_TemplatedParent_Set_To_Null()
        {
            var target = new ItemsControl();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();

            var item = (TextBlock)target.Presenter.Panel.GetVisualChildren().First();

            Assert.Null(item.TemplatedParent);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:12,代码来源:ItemsControlTests.cs

示例4: Control_Item_Should_Have_Parent_Set

        public void Control_Item_Should_Have_Parent_Set()
        {
            var target = new ItemsControl();
            var child = new Control();

            target.Template = GetTemplate();
            target.Items = new[] { child };
            target.ApplyTemplate();

            Assert.Equal(target, child.Parent);
            Assert.Equal(target, ((ILogical)child).LogicalParent);
        }
开发者ID:g4idrijs,项目名称:Perspex,代码行数:12,代码来源:ItemsControlTests.cs

示例5: Panel_Should_Have_TemplatedParent_Set_To_ItemsControl

        public void Panel_Should_Have_TemplatedParent_Set_To_ItemsControl()
        {
            var target = new ItemsControl();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();

            var presenter = target.GetTemplateChildren().OfType<ItemsPresenter>().Single();
            var panel = target.GetTemplateChildren().OfType<StackPanel>().Single();

            Assert.Equal(target, panel.TemplatedParent);
        }
开发者ID:g4idrijs,项目名称:Perspex,代码行数:13,代码来源:ItemsControlTests.cs

示例6: Clearing_Control_Item_Should_Clear_Child_Controls_Parent

        public void Clearing_Control_Item_Should_Clear_Child_Controls_Parent()
        {
            var target = new ItemsControl();
            var child = new Control();

            target.Template = GetTemplate();
            target.Items = new[] { child };
            target.ApplyTemplate();
            target.Items = null;

            Assert.Null(child.Parent);
            Assert.Null(((ILogical)child).LogicalParent);
        }
开发者ID:g4idrijs,项目名称:Perspex,代码行数:13,代码来源:ItemsControlTests.cs

示例7: Container_Should_Have_TemplatedParent_Set_To_Null

        public void Container_Should_Have_TemplatedParent_Set_To_Null()
        {
            var target = new ItemsControl();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            var container = (ContentPresenter)target.Presenter.Panel.Children[0];

            Assert.Null(container.TemplatedParent);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:13,代码来源:ItemsControlTests.cs

示例8: Item_Should_Have_TemplatedParent_Set_To_Null

        public void Item_Should_Have_TemplatedParent_Set_To_Null()
        {
            var target = new ItemsControl();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();

            var presenter = target.GetTemplateChildren().OfType<ItemsPresenter>().Single();
            var panel = target.GetTemplateChildren().OfType<StackPanel>().Single();
            var item = (TextBlock)panel.GetVisualChildren().First();

            Assert.Null(item.TemplatedParent);
        }
开发者ID:g4idrijs,项目名称:Perspex,代码行数:14,代码来源:ItemsControlTests.cs

示例9: Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren

        public void Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren()
        {
            var target = new ItemsControl();
            var child = new Control();

            target.Template = GetTemplate();
            target.Items = new[] { "Foo" };
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

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

示例10: Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren

        public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren()
        {
            var target = new ItemsControl();
            var child = new Control();

            target.Template = GetTemplate();
            target.Items = new[] { child };

            // Should appear both before and after applying template.
            Assert.Equal(new ILogical[] { child }, target.GetLogicalChildren());

            target.ApplyTemplate();

            Assert.Equal(new ILogical[] { child }, target.GetLogicalChildren());
        }
开发者ID:randydotnet,项目名称:Perspex,代码行数:15,代码来源:ItemsControlTests.cs

示例11: Should_Use_ItemTemplate_To_Create_Control

        public void Should_Use_ItemTemplate_To_Create_Control()
        {
            var target = new ItemsControl
            {
                Template = GetTemplate(),
                ItemTemplate = new FuncDataTemplate<string>(_ => new Canvas()),
            };

            target.Items = new[] { "Foo" };
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            var container = (ContentPresenter)target.Presenter.Panel.Children[0];
            container.UpdateChild();

            Assert.IsType<Canvas>(container.Child);
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:17,代码来源:ItemsControlTests.cs

示例12: Nested_TemplatedControls_Should_Be_Expanded_And_Have_Correct_TemplatedParent

        public void Nested_TemplatedControls_Should_Be_Expanded_And_Have_Correct_TemplatedParent()
        {
            var target = new ItemsControl
            {
                Template = new ControlTemplate<ItemsControl>(ItemsControlTemplate),
                Items = new[] { "Foo", }
            };

            target.ApplyTemplate();

            var scrollViewer = target.GetVisualDescendents()
                .OfType<ScrollViewer>()
                .Single();
            var types = target.GetVisualDescendents()
                .Select(x => x.GetType())
                .ToList();
            var templatedParents = target.GetVisualDescendents()
                .OfType<IControl>()
                .Select(x => x.TemplatedParent)
                .ToList();

            Assert.Equal(
                new[]
                {
                    typeof(Border),
                    typeof(ScrollViewer),
                    typeof(ScrollContentPresenter),
                    typeof(ItemsPresenter),
                    typeof(StackPanel),
                    typeof(TextBlock),
                },
                types);

            Assert.Equal(
                new object[]
                {
                    target,
                    target,
                    scrollViewer,
                    target,
                    target,
                    null
                },
                templatedParents);
        }
开发者ID:Scellow,项目名称:Perspex,代码行数:45,代码来源:TemplatedControlTests.cs

示例13: Adding_Items_Should_Fire_LogicalChildren_CollectionChanged

        public void Adding_Items_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ItemsControl();
            var items = new PerspexList<string> { "Foo" };
            var called = false;

            target.Template = GetTemplate();
            target.Items = items;
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
                called = e.Action == NotifyCollectionChangedAction.Add;

            items.Add("Bar");

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

示例14: Container_Child_Should_Have_LogicalParent_Set_To_Container

        public void Container_Child_Should_Have_LogicalParent_Set_To_Container()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var root = new Window();
                var target = new ItemsControl();

                root.Content = target;

                var templatedParent = new Button();
                target.TemplatedParent = templatedParent;
                target.Template = GetTemplate();

                target.Items = new[] { "Foo" };

                root.ApplyTemplate();
                target.ApplyTemplate();
                target.Presenter.ApplyTemplate();

                var container = (ContentPresenter)target.Presenter.Panel.Children[0];

                Assert.Equal(container, container.Child.Parent);
            }
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:24,代码来源:ItemsControlTests.cs

示例15: DataTemplate_Created_Content_Should_Be_NameScope

        public void DataTemplate_Created_Content_Should_Be_NameScope()
        {
            var items = new object[]
            {
                "foo",
            };

            var target = new ItemsControl
            {
                Template = GetTemplate(),
                Items = items,
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            var container = (ContentPresenter)target.Presenter.Panel.LogicalChildren[0];
            container.UpdateChild();

            Assert.NotNull(NameScope.GetNameScope((TextBlock)container.Child));
        }
开发者ID:jazzay,项目名称:Avalonia,代码行数:21,代码来源:ItemsControlTests.cs


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