Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new attached property TreeViewItemHelper.ToggleButtonStyle #3712

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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