Skip to content

Commit 7a7b828

Browse files
committed
Add ability to disable shadow caching, to help alleviate issue #559
1 parent 8259fcb commit 7a7b828

14 files changed

+43
-88
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,8 @@
209209
</VisualState>
210210
</VisualStateGroup>
211211
</VisualStateManager.VisualStateGroups>
212-
<AdornerDecorator x:Name="PART_Border">
213-
<AdornerDecorator.CacheMode>
214-
<BitmapCache EnableClearType="True"
215-
SnapsToDevicePixels="False" />
216-
</AdornerDecorator.CacheMode>
212+
<AdornerDecorator x:Name="PART_Border"
213+
CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
217214
<Border Background="{TemplateBinding Background}"
218215
Effect="{DynamicResource MaterialDesignShadowDepth5}" />
219216
</AdornerDecorator>

MaterialDesignThemes.Wpf/ComboBoxAssist.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using System.Windows;
7+
using System.Windows.Media;
78

89
namespace MaterialDesignThemes.Wpf
910
{

MaterialDesignThemes.Wpf/ShadowAssist.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Windows;
3+
using System.Windows.Media;
34
using System.Windows.Media.Animation;
45
using System.Windows.Media.Effects;
56
using System.Windows.Navigation;
@@ -95,6 +96,20 @@ public static void SetDarken(DependencyObject element, bool value)
9596
public static bool GetDarken(DependencyObject element)
9697
{
9798
return (bool) element.GetValue(DarkenProperty);
98-
}
99-
}
99+
}
100+
101+
public static readonly DependencyProperty CacheModeProperty = DependencyProperty.RegisterAttached(
102+
"CacheMode", typeof(CacheMode), typeof(ShadowAssist), new FrameworkPropertyMetadata(new BitmapCache { EnableClearType = true, SnapsToDevicePixels = true }, FrameworkPropertyMetadataOptions.Inherits));
103+
104+
public static void SetCacheMode(DependencyObject element, CacheMode value)
105+
{
106+
element.SetValue(CacheModeProperty, value);
107+
}
108+
109+
public static CacheMode GetCacheMode(DependencyObject element)
110+
{
111+
return (CacheMode)element.GetValue(CacheModeProperty);
112+
}
113+
114+
}
100115
}

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,7 @@
412412
<Setter.Value>
413413
<ControlTemplate TargetType="{x:Type local:ColorZone}">
414414
<Grid Background="Transparent">
415-
<AdornerDecorator>
416-
<AdornerDecorator.CacheMode>
417-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
418-
</AdornerDecorator.CacheMode>
415+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
419416
<Border Background="{TemplateBinding Background}"
420417
CornerRadius="{TemplateBinding CornerRadius}"
421418
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}">
@@ -929,10 +926,7 @@
929926
x:Name="PART_LeftDrawer"
930927
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Left}}"
931928
Panel.ZIndex="{TemplateBinding LeftDrawerZIndex}">
932-
<AdornerDecorator>
933-
<AdornerDecorator.CacheMode>
934-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
935-
</AdornerDecorator.CacheMode>
929+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
936930
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
937931
Opacity="0"
938932
Background="{TemplateBinding LeftDrawerBackground}"
@@ -945,10 +939,7 @@
945939
x:Name="PART_RightDrawer"
946940
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Right}}"
947941
Panel.ZIndex="{TemplateBinding RightDrawerZIndex}">
948-
<AdornerDecorator>
949-
<AdornerDecorator.CacheMode>
950-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
951-
</AdornerDecorator.CacheMode>
942+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
952943
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
953944
Opacity="0"
954945
Background="{TemplateBinding RightDrawerBackground}"
@@ -961,10 +952,7 @@
961952
x:Name="PART_TopDrawer"
962953
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Top}}"
963954
Panel.ZIndex="{TemplateBinding TopDrawerZIndex}">
964-
<AdornerDecorator>
965-
<AdornerDecorator.CacheMode>
966-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
967-
</AdornerDecorator.CacheMode>
955+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
968956
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
969957
Opacity="0"
970958
Background="{TemplateBinding TopDrawerBackground}"
@@ -977,10 +965,7 @@
977965
x:Name="PART_BottomDrawer"
978966
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Bottom}}"
979967
Panel.ZIndex="{TemplateBinding BottomDrawerZIndex}">
980-
<AdornerDecorator>
981-
<AdornerDecorator.CacheMode>
982-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
983-
</AdornerDecorator.CacheMode>
968+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
984969
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
985970
Opacity="0"
986971
Background="{TemplateBinding BottomDrawerBackground}"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Button.xaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
<Setter.Value>
4040
<ControlTemplate TargetType="{x:Type ButtonBase}">
4141
<Grid>
42-
<AdornerDecorator>
43-
<AdornerDecorator.CacheMode>
44-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
45-
</AdornerDecorator.CacheMode>
42+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
4643
<Border Background="{TemplateBinding Background}" CornerRadius="2"
4744
BorderThickness="{TemplateBinding BorderThickness}"
4845
BorderBrush="{TemplateBinding BorderBrush}"
@@ -181,10 +178,7 @@
181178
<Setter.Value>
182179
<ControlTemplate TargetType="{x:Type Button}">
183180
<Grid>
184-
<AdornerDecorator>
185-
<AdornerDecorator.CacheMode>
186-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
187-
</AdornerDecorator.CacheMode>
181+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
188182
<Ellipse Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"
189183
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
190184
x:Name="border">

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Card.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
<ControlTemplate TargetType="{x:Type wpf:Card}" x:Key="CardTemplate">
1313
<Grid Margin="{TemplateBinding Margin}" Background="Transparent">
14-
<AdornerDecorator>
15-
<AdornerDecorator.CacheMode>
16-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
17-
</AdornerDecorator.CacheMode>
14+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
1815
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
1916
CornerRadius="{TemplateBinding UniformCornerRadius}">
2017
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@
153153
</Grid.ColumnDefinitions>
154154
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
155155
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" UseLayoutRounding="True">
156-
<AdornerDecorator>
157-
<AdornerDecorator.CacheMode>
158-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
159-
</AdornerDecorator.CacheMode>
156+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
160157
<Border x:Name="shadow" Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2" BorderThickness="1"
161158
Effect="{DynamicResource MaterialDesignShadowDepth2}">
162159
</Border>
@@ -238,10 +235,7 @@
238235
</Grid.ColumnDefinitions>
239236
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
240237
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" UseLayoutRounding="True">
241-
<AdornerDecorator>
242-
<AdornerDecorator.CacheMode>
243-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
244-
</AdornerDecorator.CacheMode>
238+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
245239
<Border x:Name="shadow" Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2" BorderThickness="1"
246240
Effect="{DynamicResource MaterialDesignShadowDepth2}">
247241
</Border>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@
7575
PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridCell}}}"
7676
PopupAnimation="Fade">
7777
<Grid>
78-
<AdornerDecorator>
79-
<AdornerDecorator.CacheMode>
80-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
81-
</AdornerDecorator.CacheMode>
78+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
8279
<Border Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2"
8380
Margin="5,5,5,5"
8481
Effect="{StaticResource MaterialDesignShadowDepth2}"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@
8686
<Setter Property="Template">
8787
<Setter.Value>
8888
<ControlTemplate TargetType="{x:Type Calendar}">
89-
<AdornerDecorator>
90-
<!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
91-
<AdornerDecorator.CacheMode>
92-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
93-
</AdornerDecorator.CacheMode>
94-
<Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
89+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
90+
<Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
9591
<CalendarItem x:Name="PART_CalendarItem" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Style="{DynamicResource MaterialDesignCalendarItemPortrait}"/>
96-
</Border>
97-
</AdornerDecorator>
92+
</Border>
93+
</AdornerDecorator>
9894
</ControlTemplate>
9995
</Setter.Value>
10096
</Setter>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Menu.xaml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747
<Setter Property="Template">
4848
<Setter.Value>
4949
<ControlTemplate TargetType="{x:Type MenuBase}">
50-
<AdornerDecorator>
51-
<!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
52-
<AdornerDecorator.CacheMode>
53-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
54-
</AdornerDecorator.CacheMode>
50+
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
5551
<Border Background="{TemplateBinding Background}"
5652
Effect="{DynamicResource MaterialDesignShadowDepth1}"
5753
Margin="3"
@@ -176,11 +172,8 @@
176172
Focusable="False"
177173
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
178174
PopupAnimation="Slide"
179-
Placement="Bottom">
180-
<!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
181-
<Popup.CacheMode>
182-
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
183-
</Popup.CacheMode>
175+
Placement="Bottom"
176+
CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
184177
<Border x:Name="SubMenuBorder"
185178
Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}"
186179
Effect="{DynamicResource MaterialDesignShadowDepth1}"

0 commit comments

Comments
 (0)