Skip to content

Commit

Permalink
Merge pull request #3712 from MahApps/features/TreeViewItemHelper
Browse files Browse the repository at this point in the history
Add new attached property TreeViewItemHelper.ToggleButtonStyle
  • Loading branch information
punker76 authored Dec 12, 2019
2 parents 46ab84e + 0161bfb commit 9cd7028
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/MahApps.Metro/Controls/Helper/TreeViewItemHelper.cs
Original file line number Diff line number Diff line change
@@ -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));

/// <summary>
/// Gets the toggle button style used for the TreeViewItem expander.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TreeViewItem))]
public static Style GetToggleButtonStyle(UIElement element)
{
return (Style)element.GetValue(ToggleButtonStyleProperty);
}

/// <summary>
/// Sets the toggle button style used for the TreeViewItem expander.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TreeViewItem))]
public static void SetToggleButtonStyle(UIElement element, Style value)
{
element.SetValue(ToggleButtonStyleProperty, value);
}
}
}
9 changes: 6 additions & 3 deletions src/MahApps.Metro/Styles/Controls.TreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Black}" />
<Setter Property="Height" Value="16" />
<Setter Property="Margin" Value="1" />
<Setter Property="MinWidth" Value="19" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
Expand Down Expand Up @@ -77,6 +78,7 @@
<Setter Property="Controls:ItemHelper.HoverSelectedBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Accent}" />
<Setter Property="Controls:ItemHelper.SelectedBackgroundBrush" Value="{DynamicResource MahApps.Brushes.Accent2}" />
<Setter Property="Controls:ItemHelper.SelectedForegroundBrush" Value="{DynamicResource MahApps.Brushes.AccentSelectedColor}" />
<Setter Property="Controls:TreeViewItemHelper.ToggleButtonStyle" Value="{StaticResource MahApps.Styles.ToggleButton.ExpandCollapse}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Text}" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, Mode=OneWay, FallbackValue=Stretch, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
Expand All @@ -97,13 +99,14 @@
VerticalAlignment="Stretch"
Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="19" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ToggleButton x:Name="Expander"
Grid.Column="0"
ClickMode="Press"
IsChecked="{Binding Path=IsExpanded, RelativeSource={x:Static RelativeSource.TemplatedParent}, Mode=TwoWay}"
Style="{StaticResource MahApps.Styles.ToggleButton.ExpandCollapse}" />
Style="{TemplateBinding Controls:TreeViewItemHelper.ToggleButtonStyle}" />
<ContentPresenter x:Name="PART_Header"
Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Expand Down Expand Up @@ -188,7 +191,7 @@
<!-- default to 0 -->
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="1" />
<Setter Property="Padding" Value="0" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
Expand Down

0 comments on commit 9cd7028

Please sign in to comment.