From 0161bfbeec544ad0c3dd0fcde2183fc1655013c7 Mon Sep 17 00:00:00 2001 From: punker76 Date: Thu, 12 Dec 2019 15:30:20 +0100 Subject: [PATCH] Add new attached property TreeViewItemHelper.ToggleButtonStyle Add this new attached property to make it possible to set the inner ToggleButton style. The default is `MahApps.Styles.ToggleButton.ExpandCollapse`. --- .../Controls/Helper/TreeViewItemHelper.cs | 36 +++++++++++++++++++ .../Styles/Controls.TreeView.xaml | 9 +++-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/MahApps.Metro/Controls/Helper/TreeViewItemHelper.cs diff --git a/src/MahApps.Metro/Controls/Helper/TreeViewItemHelper.cs b/src/MahApps.Metro/Controls/Helper/TreeViewItemHelper.cs new file mode 100644 index 0000000000..ef30eea9be --- /dev/null +++ b/src/MahApps.Metro/Controls/Helper/TreeViewItemHelper.cs @@ -0,0 +1,36 @@ +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; + +namespace MahApps.Metro.Controls +{ + public static class TreeViewItemHelper + { + public static readonly DependencyProperty ToggleButtonStyleProperty + = DependencyProperty.RegisterAttached( + "ToggleButtonStyle", + typeof(Style), + typeof(TreeViewItemHelper), + new FrameworkPropertyMetadata((Style)null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); + + /// + /// Gets the toggle button style used for the TreeViewItem expander. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(TreeViewItem))] + public static Style GetToggleButtonStyle(UIElement element) + { + return (Style)element.GetValue(ToggleButtonStyleProperty); + } + + /// + /// Sets the toggle button style used for the TreeViewItem expander. + /// + [Category(AppName.MahApps)] + [AttachedPropertyBrowsableForType(typeof(TreeViewItem))] + public static void SetToggleButtonStyle(UIElement element, Style value) + { + element.SetValue(ToggleButtonStyleProperty, value); + } + } +} \ No newline at end of file diff --git a/src/MahApps.Metro/Styles/Controls.TreeView.xaml b/src/MahApps.Metro/Styles/Controls.TreeView.xaml index dc0dd266bc..fc53e4bd56 100644 --- a/src/MahApps.Metro/Styles/Controls.TreeView.xaml +++ b/src/MahApps.Metro/Styles/Controls.TreeView.xaml @@ -15,6 +15,7 @@ + @@ -77,6 +78,7 @@ + @@ -97,13 +99,14 @@ VerticalAlignment="Stretch" Background="Transparent"> - + + Style="{TemplateBinding Controls:TreeViewItemHelper.ToggleButtonStyle}" /> - +