private void ValueInject(DataRow drv) { DataColumnCollection dcc = Items.Columns; mainTabControl.ApplyTemplate(); for (int i = 0; i < dcc.Count; i++) { object find = LogicalTreeHelper.FindLogicalNode(mainTabControl, dcc[i].ToString()); Console.WriteLine("now find name: " + dcc[i].ToString()); if (find != null) { WrapPanel wpe = find as WrapPanel; TextBox txtbox = LogicalTreeHelper.FindLogicalNode(wpe, "TxtBox") as TextBox; Console.WriteLine("now text " + drv[dcc[i].ToString()]); Console.WriteLine("now text type " + drv[dcc[i].ToString()].GetType()); if (drv[dcc[i].ToString()] != null && drv[dcc[i].ToString()].ToString().Length > 0) { txtbox.Text = drv[dcc[i].ToString()].ToString(); } else { txtbox.Text = ""; } } } nowtab = 0; }
public void Setting_SelectedItem_Should_Set_SelectedTab() { var target = new TabControl { Template = new ControlTemplate <TabControl>(CreateTabControlTemplate), Items = new[] { new TabItem { Name = "first", Content = "foo", }, new TabItem { Name = "second", Content = "bar", }, } }; target.ApplyTemplate(); target.SelectedItem = target.Items.Cast <TabItem>().ElementAt(1); Assert.Same(target.SelectedTab, target.SelectedItem); }
public void Non_IHeadered_Control_Items_Should_Be_Ignored() { var items = new[] { new TextBlock { Text = "foo" }, new TextBlock { Text = "bar" }, }; var target = new TabControl { Template = new FuncControlTemplate <TabControl>(CreateTabControlTemplate), Items = items, }; target.ApplyTemplate(); var result = target.TabStrip.GetLogicalChildren() .OfType <TabStripItem>() .Select(x => x.Content) .ToList(); Assert.Equal(new object[] { string.Empty, string.Empty }, result); }
public void Setting_SelectedItem_Should_Set_SelectedTab() { var target = new TabControl { Template = new ControlTemplate<TabControl>(CreateTabControlTemplate), Items = new[] { new TabItem { Name = "first", Content = "foo", }, new TabItem { Name = "second", Content = "bar", }, } }; target.ApplyTemplate(); target.SelectedItem = target.Items.Cast<TabItem>().ElementAt(1); Assert.Same(target.SelectedTab, target.SelectedItem); }
public void First_Tab_Should_Be_Selected_By_Default() { TabItem selected; var target = new TabControl { Template = TabControlTemplate(), Items = new[] { (selected = new TabItem { Name = "first", Content = "foo", }), new TabItem { Name = "second", Content = "bar", }, } }; target.ApplyTemplate(); Assert.Equal(0, target.SelectedIndex); Assert.Equal(selected, target.SelectedItem); }
public void First_Tab_Should_Be_Selected_By_Default() { TabItem selected; var target = new TabControl { Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate), Items = new[] { (selected = new TabItem { Name = "first", Content = "foo", }), new TabItem { Name = "second", Content = "bar", }, } }; target.ApplyTemplate(); Assert.Equal(0, target.SelectedIndex); Assert.Equal(selected, target.SelectedItem); }
public void Removal_Should_Set_Next_Tab() { var collection = new ObservableCollection <TabItem>() { new TabItem { Name = "first", Content = "foo", }, new TabItem { Name = "second", Content = "bar", }, new TabItem { Name = "3rd", Content = "barf", }, }; var target = new TabControl { Template = TabControlTemplate(), Items = collection, }; target.ApplyTemplate(); target.SelectedItem = collection[1]; collection.RemoveAt(1); // compare with former [2] now [1] == "3rd" Assert.Same(collection[1], target.SelectedItem); }
public void DataContexts_Should_Be_Correctly_Set() { var items = new object[] { "Foo", new Item("Bar"), new TextBlock { Text = "Baz" }, new TabItem { Content = "Qux" }, new TabItem { Content = new TextBlock { Text = "Bob" } } }; var target = new TabControl { Template = new FuncControlTemplate <TabControl>(CreateTabControlTemplate), DataContext = "Base", DataTemplates = new DataTemplates { new FuncDataTemplate <Item>(x => new Button { Content = x }) }, Items = items, }; target.ApplyTemplate(); var carousel = (Carousel)target.Pages; var dataContext = ((TextBlock)carousel.Presenter.Panel.GetLogicalChildren().Single()).DataContext; Assert.Equal(items[0], dataContext); target.SelectedIndex = 1; dataContext = ((Button)carousel.Presenter.Panel.GetLogicalChildren().Single()).DataContext; Assert.Equal(items[1], dataContext); target.SelectedIndex = 2; dataContext = ((TextBlock)carousel.Presenter.Panel.GetLogicalChildren().Single()).DataContext; Assert.Equal("Base", dataContext); target.SelectedIndex = 3; dataContext = ((TextBlock)carousel.Presenter.Panel.GetLogicalChildren().Single()).DataContext; Assert.Equal("Qux", dataContext); target.SelectedIndex = 4; dataContext = ((TextBlock)carousel.Presenter.Panel.GetLogicalChildren().Single()).DataContext; Assert.Equal("Base", dataContext); }
private void ApplyTemplate(TabControl target) { target.ApplyTemplate(); var carousel = (Carousel)target.Pages; carousel.ApplyTemplate(); carousel.Presenter.ApplyTemplate(); var tabStrip = (TabStrip)target.TabStrip; tabStrip.ApplyTemplate(); tabStrip.Presenter.ApplyTemplate(); }
private void ApplyTemplate(TabControl target) { target.ApplyTemplate(); target.Presenter.ApplyTemplate(); foreach (var tabItem in target.GetLogicalChildren().OfType <TabItem>()) { tabItem.Template = TabItemTemplate(); tabItem.ApplyTemplate(); ((ContentPresenter)tabItem.Presenter).UpdateChild(); } target.ContentPart.ApplyTemplate(); }
public void Logical_Child_Should_Be_Selected_Tab_Content() { var target = new TabControl { Template = new ControlTemplate <TabControl>(CreateTabControlTemplate), Items = new[] { new TabItem { Content = "foo" }, new TabItem { Content = "bar" }, }, }; target.ApplyTemplate(); Assert.Equal(1, target.GetLogicalChildren().Count()); Assert.Equal("foo", ((TextBlock)target.GetLogicalChildren().First()).Text); }
public void Logical_Child_Should_Be_SelectedContent() { var target = new TabControl { Template = new ControlTemplate<TabControl>(this.CreateTabControlTemplate), Items = new[] { new TabItem { Content = "foo" }, new TabItem { Content = "bar" }, }, }; target.ApplyTemplate(); Assert.Equal(1, target.GetLogicalChildren().Count()); Assert.Equal("foo", ((TextBlock)target.GetLogicalChildren().First()).Text); }
public void Logical_Children_Should_Be_TabItems() { var items = new[] { new TabItem { Content = "foo" }, new TabItem { Content = "bar" }, }; var target = new TabControl { Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate), Items = items, }; Assert.Equal(items, target.GetLogicalChildren()); target.ApplyTemplate(); Assert.Equal(items, target.GetLogicalChildren()); }
public void Logical_Children_Should_Be_TabItems() { var items = new[] { new TabItem { Content = "foo" }, new TabItem { Content = "bar" }, }; var target = new TabControl { Template = TabControlTemplate(), Items = items, }; Assert.Equal(items, target.GetLogicalChildren()); target.ApplyTemplate(); Assert.Equal(items, target.GetLogicalChildren()); }
public void Setting_SelectedTab_Should_Set_SelectedItem() { var target = new TabControl { Template = ControlTemplate.Create<TabControl>(this.CreateTabControlTemplate), Items = new[] { new TabItem { Name = "first" }, new TabItem { Name = "second" }, } }; target.ApplyTemplate(); target.SelectedTab = target.Items.Cast<TabItem>().ElementAt(1); Assert.Same(target.SelectedItem, target.SelectedTab); }
public void Non_IHeadered_Control_Items_Should_Be_Ignored() { var items = new[] { new TextBlock { Text = "foo" }, new TextBlock { Text = "bar" }, }; var target = new TabControl { Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate), Items = items, }; target.ApplyTemplate(); var result = target.TabStrip.GetLogicalChildren() .OfType<TabStripItem>() .Select(x => x.Content) .ToList(); Assert.Equal(new object[] { string.Empty, string.Empty }, result); }
public void DataContexts_Should_Be_Correctly_Set() { var items = new object[] { "Foo", new Item("Bar"), new TextBlock { Text = "Baz" }, new TabItem { Content = "Qux" }, new TabItem { Content = new TextBlock { Text = "Bob" } } }; var target = new TabControl { Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate), DataContext = "Base", DataTemplates = new DataTemplates { new FuncDataTemplate<Item>(x => new Button { Content = x }) }, Items = items, }; target.ApplyTemplate(); var dataContext = ((TextBlock)target.GetLogicalChildren().Single()).DataContext; Assert.Equal(items[0], dataContext); target.SelectedIndex = 1; dataContext = ((Button)target.GetLogicalChildren().Single()).DataContext; Assert.Equal(items[1], dataContext); target.SelectedIndex = 2; dataContext = ((TextBlock)target.GetLogicalChildren().Single()).DataContext; Assert.Equal("Base", dataContext); target.SelectedIndex = 3; dataContext = ((TextBlock)target.GetLogicalChildren().Single()).DataContext; Assert.Equal("Qux", dataContext); target.SelectedIndex = 4; dataContext = ((TextBlock)target.GetLogicalChildren().Single()).DataContext; Assert.Equal("Base", dataContext); }
public void SelectedContent_Should_Initially_Be_First_Tab_Content() { var target = new TabControl { Template = new ControlTemplate<TabControl>(this.CreateTabControlTemplate), Items = new[] { new TabItem { Name = "first", Content = "foo", }, new TabItem { Name = "second", Content = "bar", }, } }; target.ApplyTemplate(); Assert.Equal("foo", target.SelectedContent); }
public void Removal_Should_Set_Next_Tab() { var collection = new ObservableCollection<TabItem>() { new TabItem { Name = "first", Content = "foo", }, new TabItem { Name = "second", Content = "bar", }, new TabItem { Name = "3rd", Content = "barf", }, }; var target = new TabControl { Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate), Items = collection, }; target.ApplyTemplate(); target.SelectedItem = collection[1]; collection.RemoveAt(1); // compare with former [2] now [1] == "3rd" Assert.Same(collection[1], target.SelectedItem); }