Skip to content

Commit 1311512

Browse files
committed
allow for coloured headers in mahapps flyouts #121
1 parent d103721 commit 1311512

File tree

9 files changed

+108
-52
lines changed

9 files changed

+108
-52
lines changed

MahMaterialDragablzMashUp/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Title="Material-MahApps-Dragablz Mash Up" Height="350" Width="525">
1313
<controls:MetroWindow.Flyouts>
1414
<controls:FlyoutsControl>
15-
<controls:Flyout x:Name="LeftFlyout" Position="Left">
15+
<controls:Flyout x:Name="LeftFlyout" Position="Left" Header="Settings">
1616
<mahMaterialDragablzMashUp:FlyoutContent />
1717
</controls:Flyout>
1818
</controls:FlyoutsControl>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using MaterialDesignThemes.Wpf;
8+
9+
namespace MaterialDesignThemes.MahApps
10+
{
11+
public static class FlyoutAssist
12+
{
13+
public static readonly DependencyProperty HeaderColorModeProperty = DependencyProperty.RegisterAttached(
14+
"HeaderColorMode", typeof(ColorZoneMode), typeof(FlyoutAssist), new FrameworkPropertyMetadata(default(ColorZoneMode), FrameworkPropertyMetadataOptions.Inherits));
15+
16+
public static void SetHeaderColorMode(DependencyObject element, ColorZoneMode value)
17+
{
18+
element.SetValue(HeaderColorModeProperty, value);
19+
}
20+
21+
public static ColorZoneMode GetHeaderColorMode(DependencyObject element)
22+
{
23+
return (ColorZoneMode)element.GetValue(HeaderColorModeProperty);
24+
}
25+
26+
public static readonly DependencyProperty HeaderShadowDepthProperty = DependencyProperty.RegisterAttached(
27+
"HeaderShadowDepth", typeof (ShadowDepth), typeof (FlyoutAssist), new FrameworkPropertyMetadata(default(ShadowDepth), FrameworkPropertyMetadataOptions.Inherits));
28+
29+
public static void SetHeaderShadowDepth(DependencyObject element, ShadowDepth value)
30+
{
31+
element.SetValue(HeaderShadowDepthProperty, value);
32+
}
33+
34+
public static ShadowDepth GetHeaderShadowDepth(DependencyObject element)
35+
{
36+
return (ShadowDepth) element.GetValue(HeaderShadowDepthProperty);
37+
}
38+
}
39+
}

MaterialDesignThemes.MahApps/MaterialDesignThemes.MahApps.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
</Page>
8282
</ItemGroup>
8383
<ItemGroup>
84+
<Compile Include="FlyoutAssist.cs" />
8485
<Compile Include="Properties\AssemblyInfo.cs">
8586
<SubType>Code</SubType>
8687
</Compile>

MaterialDesignThemes.MahApps/Themes/MaterialDesignTheme.MahApps.Flyout.xaml

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,57 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
44
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
5-
xmlns:Actions="clr-namespace:MahApps.Metro.Actions;assembly=MahApps.Metro" >
6-
7-
<ResourceDictionary.MergedDictionaries>
8-
9-
</ResourceDictionary.MergedDictionaries>
5+
xmlns:Actions="clr-namespace:MahApps.Metro.Actions;assembly=MahApps.Metro"
6+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
7+
xmlns:mahApps="clr-namespace:MaterialDesignThemes.MahApps">
108

119
<DataTemplate x:Key="HeaderTemplate"
1210
x:Shared="False">
13-
<DockPanel x:Name="dpHeader"
14-
Margin="10,25,10,10"
15-
VerticalAlignment="Center"
16-
LastChildFill="True">
17-
<Button x:Name="nav"
18-
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:Flyout}}, Path=CloseCommand, Mode=OneWay}"
19-
DockPanel.Dock="Left"
20-
Style="{DynamicResource MaterialDesignToolButton}"
21-
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=CloseButtonVisibility}"
22-
Height="40"
23-
Width="40"
24-
FontFamily="Segoe UI Symbol"
25-
FontSize="16"
26-
VerticalAlignment="Bottom">
27-
<i:Interaction.Triggers>
28-
<i:EventTrigger EventName="Click">
29-
<Actions:SetFlyoutOpenAction TargetObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:Flyout}}}"
30-
Value="False" />
31-
</i:EventTrigger>
32-
</i:Interaction.Triggers>
33-
<Viewbox Width="24" Height="24" RenderTransformOrigin="0.5,0.5">
34-
<Viewbox.RenderTransform>
35-
<TransformGroup>
36-
<ScaleTransform ScaleY="1" ScaleX="-1"/>
37-
<SkewTransform AngleY="0" AngleX="0"/>
38-
<RotateTransform Angle="0"/>
39-
<TranslateTransform/>
40-
</TransformGroup>
41-
</Viewbox.RenderTransform>
42-
<Canvas Width="24" Height="24">
43-
<Path Data="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"
44-
Fill="{DynamicResource MaterialDesignBody}" />
45-
</Canvas>
46-
</Viewbox>
47-
</Button>
48-
<TextBlock Text="{Binding}"
49-
x:Name="PART_BackButton"
50-
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=TitleVisibility}"
51-
FontSize="{StaticResource FlyoutHeaderFontSize}"
52-
Margin="15,0,0,0"
53-
VerticalAlignment="Center" />
54-
</DockPanel>
11+
<wpf:ColorZone
12+
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mahApps:FlyoutAssist.HeaderColorMode)}"
13+
wpf:ShadowAssist.ShadowDepth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mahApps:FlyoutAssist.HeaderShadowDepth)}">
14+
<DockPanel x:Name="dpHeader"
15+
Margin="10,25,10,10"
16+
VerticalAlignment="Center"
17+
LastChildFill="True">
18+
<Button x:Name="nav"
19+
Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:Flyout}}, Path=CloseCommand, Mode=OneWay}"
20+
DockPanel.Dock="Left"
21+
Style="{DynamicResource MaterialDesignToolButton}"
22+
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=CloseButtonVisibility}"
23+
Height="40"
24+
Width="40"
25+
FontSize="16"
26+
VerticalAlignment="Bottom">
27+
<i:Interaction.Triggers>
28+
<i:EventTrigger EventName="Click">
29+
<Actions:SetFlyoutOpenAction TargetObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:Flyout}}}"
30+
Value="False" />
31+
</i:EventTrigger>
32+
</i:Interaction.Triggers>
33+
<Viewbox Width="24" Height="24" RenderTransformOrigin="0.5,0.5">
34+
<Viewbox.RenderTransform>
35+
<TransformGroup>
36+
<ScaleTransform ScaleY="1" ScaleX="-1"/>
37+
<SkewTransform AngleY="0" AngleX="0"/>
38+
<RotateTransform Angle="0"/>
39+
<TranslateTransform/>
40+
</TransformGroup>
41+
</Viewbox.RenderTransform>
42+
<Canvas Width="24" Height="24">
43+
<Path Data="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"
44+
Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:ColorZone}, Path=Foreground}" />
45+
</Canvas>
46+
</Viewbox>
47+
</Button>
48+
<TextBlock Text="{Binding}"
49+
x:Name="PART_BackButton"
50+
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:Flyout}}, Path=TitleVisibility}"
51+
FontSize="{StaticResource FlyoutHeaderFontSize}"
52+
Margin="15,0,0,0"
53+
VerticalAlignment="Center" />
54+
</DockPanel>
55+
</wpf:ColorZone>
5556
<DataTemplate.Triggers>
5657
<DataTrigger Binding="{Binding Position, RelativeSource={RelativeSource AncestorType={x:Type Controls:Flyout}}}"
5758
Value="Left">
@@ -258,6 +259,10 @@
258259
Value="Stretch" />
259260
<Setter Property="VerticalContentAlignment"
260261
Value="Stretch" />
262+
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth"
263+
Value="Depth2" />
264+
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode"
265+
Value="PrimaryMid" />
261266
<Setter Property="HeaderTemplate"
262267
Value="{StaticResource HeaderTemplate}" />
263268
<Setter Property="Template"
@@ -267,6 +272,16 @@
267272
<Setter Property="Foreground"
268273
Value="{DynamicResource MaterialDesignBody}" />
269274
<Setter Property="Background"
270-
Value="{DynamicResource MaterialDesignPaper}" />
275+
Value="{DynamicResource MaterialDesignPaper}" />
276+
<Style.Triggers>
277+
<Trigger Property="TitleVisibility" Value="Collapsed">
278+
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth" Value="Depth0" />
279+
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode" Value="Standard" />
280+
</Trigger>
281+
<Trigger Property="TitleVisibility" Value="Hidden">
282+
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth" Value="Depth0" />
283+
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode" Value="Standard" />
284+
</Trigger>
285+
</Style.Triggers>
271286
</Style>
272287
</ResourceDictionary>

MaterialDesignThemes.Wpf/ComboBoxAssist.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public static class ComboBoxAssist
2424
Key.Enter,
2525
Key.Home,
2626
Key.End,
27-
//Key.Right,
28-
//Key.Left,
2927
Key.PageUp,
3028
Key.PageDown,
3129
Key.Oem5

MaterialDesignThemes.Wpf/Converters/ShadowConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static ShadowConverter()
2121

2222
ShadowsDictionary = new Dictionary<ShadowDepth, DropShadowEffect>
2323
{
24+
{ ShadowDepth.Depth0, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth0"] },
2425
{ ShadowDepth.Depth1, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth1"] },
2526
{ ShadowDepth.Depth2, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth2"] },
2627
{ ShadowDepth.Depth3, (DropShadowEffect)resourceDictionary["MaterialDesignShadowDepth3"] },

MaterialDesignThemes.Wpf/ShadowAssist.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace MaterialDesignThemes.Wpf
88
{
99
public enum ShadowDepth
1010
{
11+
Depth0,
1112
Depth1,
1213
Depth2,
1314
Depth3,

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
356356
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
357357
<Setter Property="VerticalAlignment" Value="Top" />
358-
<Setter Property="IsTabStop" Value="False" />
358+
<Setter Property="IsTabStop" Value="False" />
359359
<Setter Property="Template">
360360
<Setter.Value>
361361
<ControlTemplate TargetType="{x:Type local:ColorZone}">

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Shadows.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<Color x:Key="MaterialDesignShadow">#AA000000</Color>
88

9+
<DropShadowEffect x:Key="MaterialDesignShadowDepth0" BlurRadius="0" ShadowDepth="0" Direction="270" Opacity="0" po:Freeze="True" />
910
<DropShadowEffect x:Key="MaterialDesignShadowDepth1" BlurRadius="5" ShadowDepth="1" Direction="270" Color="{StaticResource MaterialDesignShadow}" Opacity=".42" po:Freeze="True" />
1011
<DropShadowEffect x:Key="MaterialDesignShadowDepth2" BlurRadius="8" ShadowDepth="1.5" Direction="270" Color="{StaticResource MaterialDesignShadow}" Opacity=".42" po:Freeze="True" />
1112
<DropShadowEffect x:Key="MaterialDesignShadowDepth3" BlurRadius="14" ShadowDepth="4.5" Direction="270" Color="{StaticResource MaterialDesignShadow}" Opacity=".42" po:Freeze="True" />

0 commit comments

Comments
 (0)