Skip to content

Commit 0c36abf

Browse files
authored
Allow changing expander header background through ExpanderAssist (#2164)
* allow changing expander header background through ExpanderAssist * switched expander header background property to use Brush instead of SolidColorBrush moved binding to a higher control in stack
1 parent 619a370 commit 0c36abf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

MaterialDesignThemes.Wpf/ExpanderAssist.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Controls;
4+
using System.Windows.Media;
45

56
namespace MaterialDesignThemes.Wpf
67
{
@@ -41,5 +42,15 @@ public static double GetHeaderFontSize(Expander element)
4142
public static void SetHeaderFontSize(Expander element, double value)
4243
=> element.SetValue(HeaderFontSizeProperty, value);
4344
#endregion
45+
46+
#region AttachedProperty : HeaderBackgroundProperty
47+
public static readonly DependencyProperty HeaderBackgroundProperty
48+
= DependencyProperty.RegisterAttached("HeaderBackground", typeof(Brush), typeof(ExpanderAssist));
49+
50+
public static Brush GetHeaderBackground(Expander element)
51+
=> (Brush)element.GetValue(HeaderBackgroundProperty);
52+
public static void SetHeaderBackground(Expander element, Brush value)
53+
=> element.SetValue(HeaderBackgroundProperty, value);
54+
#endregion
4455
}
4556
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Expander.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@
247247
IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
248248
Style="{StaticResource MaterialDesignHorizontalHeaderStyle}"
249249
TextElement.FontSize="{TemplateBinding wpf:ExpanderAssist.HeaderFontSize}"
250-
Opacity="0.87"
250+
Opacity="0.87"
251251
Foreground="{TemplateBinding Foreground}"
252+
Background="{TemplateBinding wpf:ExpanderAssist.HeaderBackground}"
252253
Content="{TemplateBinding Header}"
253254
ContentTemplate="{TemplateBinding HeaderTemplate}"
254255
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"

0 commit comments

Comments
 (0)