예제 #1
0
        public void Items_Should_Be_Created()
        {
            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items = CreateTestTreeData(),
                DataTemplates = CreateNodeDataTemplate(),
            };

            target.ApplyTemplate();

            Assert.Equal(new[] { "Root" }, ExtractItemHeader(target, 0));
            Assert.Equal(new[] { "Child1", "Child2" }, ExtractItemHeader(target, 1));
            Assert.Equal(new[] { "Grandchild2a" }, ExtractItemHeader(target, 2));
        }
예제 #2
0
        public void Root_ItemContainerGenerator_Containers_Should_Be_Root_Containers()
        {
            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items = CreateTestTreeData(),
                DataTemplates = CreateNodeDataTemplate(),
            };

            target.ApplyTemplate();

            var container = (TreeViewItem)target.ItemContainerGenerator.Containers.Single();
            var header = (TextBlock)container.Header;
            Assert.Equal("Root", header.Text);
        }
예제 #3
0
        public void Items_Should_Be_Created()
        {
            var target = new TreeView
            {
                Template      = CreateTreeViewTemplate(),
                Items         = CreateTestTreeData(),
                DataTemplates = CreateNodeDataTemplate(),
            };

            target.ApplyTemplate();

            Assert.Equal(new[] { "Root" }, ExtractItemHeader(target, 0));
            Assert.Equal(new[] { "Child1", "Child2" }, ExtractItemHeader(target, 1));
            Assert.Equal(new[] { "Grandchild2a" }, ExtractItemHeader(target, 2));
        }
예제 #4
0
        public void Root_ItemContainerGenerator_Containers_Should_Be_Root_Containers()
        {
            var target = new TreeView
            {
                Template      = CreateTreeViewTemplate(),
                Items         = CreateTestTreeData(),
                DataTemplates = CreateNodeDataTemplate(),
            };

            target.ApplyTemplate();

            var container = (TreeViewItem)target.ItemContainerGenerator.Containers.Single();
            var header    = (TextBlock)container.Header;

            Assert.Equal("Root", header.Text);
        }
예제 #5
0
        public void LogicalChildren_Should_Be_Set()
        {
            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items    = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            var result = target.GetLogicalChildren()
                         .OfType <TreeViewItem>()
                         .Select(x => x.Header)
                         .OfType <TextBlock>()
                         .Select(x => x.Text)
                         .ToList();

            Assert.Equal(new[] { "Foo", "Bar", "Baz " }, result);
        }
예제 #6
0
        public void Control_Item_Should_Not_Be_NameScope()
        {
            var items = new object[]
            {
                new TreeViewItem(),
            };

            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items = items,
            };

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

            var item = target.Presenter.Panel.LogicalChildren[0];
            Assert.Null(NameScope.GetNameScope((TreeViewItem)item));
        }
예제 #7
0
        public void DataTemplate_Created_Item_Should_Be_NameScope()
        {
            var items = new object[]
            {
                "foo",
            };

            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items    = items,
            };

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

            var item = target.Presenter.Panel.LogicalChildren[0];

            Assert.NotNull(NameScope.GetNameScope((TreeViewItem)item));
        }
예제 #8
0
        public void DataContexts_Should_Be_Correctly_Set()
        {
            var items = new object[]
            {
                "Foo",
                new Node {
                    Value = "Bar"
                },
                new TextBlock {
                    Text = "Baz"
                },
                new TreeViewItem {
                    Header = "Qux"
                },
            };

            var target = new TreeView
            {
                Template      = CreateTreeViewTemplate(),
                DataContext   = "Base",
                DataTemplates = new DataTemplates
                {
                    new FuncDataTemplate <Node>(x => new Button {
                        Content = x
                    })
                },
                Items = items,
            };

            target.ApplyTemplate();

            var dataContexts = target.Presenter.Panel.Children
                               .Cast <Control>()
                               .Select(x => x.DataContext)
                               .ToList();

            Assert.Equal(
                new object[] { items[0], items[1], "Base", "Base" },
                dataContexts);
        }
예제 #9
0
 private void ApplyTemplates(TreeView tree)
 {
     tree.ApplyTemplate();
     tree.Presenter.ApplyTemplate();
     ApplyTemplates(tree.Presenter.Panel.Children);
 }
예제 #10
0
 private void ApplyTemplates(TreeView tree)
 {
     tree.ApplyTemplate();
     tree.Presenter.ApplyTemplate();
     ApplyTemplates(tree.Presenter.Panel.Children);
 }
예제 #11
0
        public void DataContexts_Should_Be_Correctly_Set()
        {
            var items = new object[]
            {
                "Foo",
                new Node { Value = "Bar" },
                new TextBlock { Text = "Baz" },
                new TreeViewItem { Header = "Qux" },
            };

            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                DataContext = "Base",
                DataTemplates = new DataTemplates
                {
                    new FuncDataTemplate<Node>(x => new Button { Content = x })
                },
                Items = items,
            };

            target.ApplyTemplate();

            var dataContexts = target.Presenter.Panel.Children
                .Cast<Control>()
                .Select(x => x.DataContext)
                .ToList();

            Assert.Equal(
                new object[] { items[0], items[1], "Base", "Base" },
                dataContexts);
        }
예제 #12
0
        public void LogicalChildren_Should_Be_Set()
        {
            var target = new TreeView
            {
                Template = CreateTreeViewTemplate(),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            var result = target.GetLogicalChildren()
                .OfType<TreeViewItem>()
                .Select(x => x.Header)
                .OfType<TextBlock>()
                .Select(x => x.Text)
                .ToList();

            Assert.Equal(new[] { "Foo", "Bar", "Baz " }, result);
        }