public HBoxArea () { itemsControl = new ItemsControl () { ItemsPanel = panel }; Content = itemsControl; itemsControl.ItemTemplate = new DataTemplate (Factory); BindingOperations.SetBinding (this, "DataContext.Tokens", itemsControl.GetProperty ("ItemsSource")); }
private static UIElement TabControlTemplate (UIElement element) { var grid = new Grid () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; grid.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto }); grid.RowDefinitions.Add (new RowDefinition ()); grid.ColumnDefinitions.Add (new ColumnDefinition ()); var selectedTabContent = new ContentControl () { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; BindingOperations.SetBinding (element, "SelectedItem.Content", selectedTabContent.GetProperty ("Content")); var headerPanel = new ItemsControl () { ItemsPanel = new StackPanel() { Orientation = Orientation.Horizontal }, ItemTemplate = new DataTemplate(TabHeaderTemplate), }; BindingOperations.SetBinding (element.GetProperty ("Items"), headerPanel.GetProperty ("ItemsSource")); grid.Children.Add (headerPanel); grid.Children.Add (selectedTabContent); grid.SetRow (0, headerPanel); grid.SetColumn (0, headerPanel); grid.SetRow (1, selectedTabContent); grid.SetColumn (0, selectedTabContent); var border = new Border () { Child = grid, }; BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding")); BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background")); BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness")); BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor")); return border; }