public void DataContexts_Should_Be_Correctly_Set() { var items = new object[] { "Foo", new Item("Bar"), new TextBlock { Text = "Baz" }, new TreeViewItem { Header = "Qux" }, }; var target = new TreeView { Template = new ControlTemplate(CreateTreeViewTemplate), DataContext = "Base", DataTemplates = new DataTemplates { new FuncDataTemplate<Item>(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); }
public void LogicalChildren_Should_Be_Set() { var target = new TreeView { Template = new ControlTemplate(CreateTreeViewTemplate), Items = new[] { "Foo", "Bar", "Baz " }, }; target.ApplyTemplate(); Assert.Equal(3, target.GetLogicalChildren().Count()); foreach (var child in target.GetLogicalChildren()) { Assert.IsType<TreeViewItem>(child); } }