private Control Template(TreeViewItem control) { return new StackPanel { Children = new Controls { new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(new GridLength(16, GridUnitType.Pixel)), new ColumnDefinition(GridLength.Auto), }, Children = new Controls { new ToggleButton { Classes = new Classes("expander"), [~~ToggleButton.IsCheckedProperty] = control[~TreeViewItem.IsExpandedProperty], }, new Border { Name = "header", [~Border.BackgroundProperty] = control[~TreeViewItem.BackgroundProperty], [Grid.ColumnProperty] = 1, Child = new ContentPresenter { [~ContentPresenter.ContentProperty] = control[~TreeViewItem.HeaderProperty], }, } } }, new ItemsPresenter { Name = "itemsPresenter", Margin = new Thickness(24, 0, 0, 0), [~ItemsPresenter.ItemsProperty] = control[~TreeViewItem.ItemsProperty], [~ItemsPresenter.ItemsPanelProperty] = control[~TreeViewItem.ItemsPanelProperty], [~ItemsPresenter.IsVisibleProperty] = control[~TreeViewItem.IsExpandedProperty], } } }; }
/// <summary> /// The default template for the <see cref="TreeViewItem"/> control. /// </summary> /// <param name="control">The control being styled.</param> /// <returns>The root of the instantiated template.</returns> public static Control Template(TreeViewItem control) { return new StackPanel { Children = new Controls { new Grid { ColumnDefinitions = new ColumnDefinitions { new ColumnDefinition(new GridLength(16, GridUnitType.Pixel)), new ColumnDefinition(GridLength.Auto), }, Children = new Controls { new ToggleButton { Classes = new Classes("expander"), Focusable = false, [~~ToggleButton.IsCheckedProperty] = control[~TreeViewItem.IsExpandedProperty], }, new Border { Name = "header", [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [Grid.ColumnProperty] = 1, Child = new ContentPresenter { [~ContentPresenter.ContentProperty] = control[~HeaderedItemsControl.HeaderProperty], }, }, new Rectangle { Name = "focus", Stroke = Brushes.Black, StrokeThickness = 1, StrokeDashArray = new PerspexList<double>(1, 2), [Grid.ColumnProperty] = 1, [!Rectangle.IsVisibleProperty] = control[!TreeViewItem.IsFocusedProperty], } } }, new ItemsPresenter { Name = "itemsPresenter", Margin = new Thickness(24, 0, 0, 0), [~ItemsPresenter.ItemsProperty] = control[~ItemsControl.ItemsProperty], [~ItemsPresenter.ItemsPanelProperty] = control[~ItemsControl.ItemsPanelProperty], [~Visual.IsVisibleProperty] = control[~TreeViewItem.IsExpandedProperty], } } }; }