Permalink
Browse files

Add ability to disable shadow caching, to help alleviate issue #559

  • Loading branch information...
1 parent 8259fcb commit 7a7b8288607a6c3454c26db15e86ed5e50049423 @ButchersBoy committed Nov 25, 2016
@@ -209,11 +209,8 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
- <AdornerDecorator x:Name="PART_Border">
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True"
- SnapsToDevicePixels="False" />
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator x:Name="PART_Border"
+ CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}"
Effect="{DynamicResource MaterialDesignShadowDepth5}" />
</AdornerDecorator>
@@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows;
+using System.Windows.Media;
namespace MaterialDesignThemes.Wpf
{
@@ -1,5 +1,6 @@
using System;
using System.Windows;
+using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Navigation;
@@ -95,6 +96,20 @@ public static void SetDarken(DependencyObject element, bool value)
public static bool GetDarken(DependencyObject element)
{
return (bool) element.GetValue(DarkenProperty);
- }
- }
+ }
+
+ public static readonly DependencyProperty CacheModeProperty = DependencyProperty.RegisterAttached(
+ "CacheMode", typeof(CacheMode), typeof(ShadowAssist), new FrameworkPropertyMetadata(new BitmapCache { EnableClearType = true, SnapsToDevicePixels = true }, FrameworkPropertyMetadataOptions.Inherits));
+
+ public static void SetCacheMode(DependencyObject element, CacheMode value)
+ {
+ element.SetValue(CacheModeProperty, value);
+ }
+
+ public static CacheMode GetCacheMode(DependencyObject element)
+ {
+ return (CacheMode)element.GetValue(CacheModeProperty);
+ }
+
+ }
}
@@ -412,10 +412,7 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorZone}">
<Grid Background="Transparent">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}"
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}">
@@ -929,10 +926,7 @@
x:Name="PART_LeftDrawer"
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Left}}"
Panel.ZIndex="{TemplateBinding LeftDrawerZIndex}">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
Opacity="0"
Background="{TemplateBinding LeftDrawerBackground}"
@@ -945,10 +939,7 @@
x:Name="PART_RightDrawer"
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Right}}"
Panel.ZIndex="{TemplateBinding RightDrawerZIndex}">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
Opacity="0"
Background="{TemplateBinding RightDrawerBackground}"
@@ -961,10 +952,7 @@
x:Name="PART_TopDrawer"
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Top}}"
Panel.ZIndex="{TemplateBinding TopDrawerZIndex}">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
Opacity="0"
Background="{TemplateBinding TopDrawerBackground}"
@@ -977,10 +965,7 @@
x:Name="PART_BottomDrawer"
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Bottom}}"
Panel.ZIndex="{TemplateBinding BottomDrawerZIndex}">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShadowAssist.CacheMode)}">
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
Opacity="0"
Background="{TemplateBinding BottomDrawerBackground}"
@@ -39,10 +39,7 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type ButtonBase}">
<Grid>
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}" CornerRadius="2"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
@@ -181,10 +178,7 @@
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Ellipse Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"
Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
x:Name="border">
@@ -11,10 +11,7 @@
<ControlTemplate TargetType="{x:Type wpf:Card}" x:Key="CardTemplate">
<Grid Margin="{TemplateBinding Margin}" Background="Transparent">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
CornerRadius="{TemplateBinding UniformCornerRadius}">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
@@ -153,10 +153,7 @@
</Grid.ColumnDefinitions>
<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">
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" UseLayoutRounding="True">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="shadow" Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2" BorderThickness="1"
Effect="{DynamicResource MaterialDesignShadowDepth2}">
</Border>
@@ -238,10 +235,7 @@
</Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" UseLayoutRounding="True">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="shadow" Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2" BorderThickness="1"
Effect="{DynamicResource MaterialDesignShadowDepth2}">
</Border>
@@ -75,10 +75,7 @@
PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridCell}}}"
PopupAnimation="Fade">
<Grid>
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{DynamicResource MaterialDesignPaper}" CornerRadius="2"
Margin="5,5,5,5"
Effect="{StaticResource MaterialDesignShadowDepth2}"
@@ -86,15 +86,11 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Calendar}">
- <AdornerDecorator>
- <!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
- <Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
+ <Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
<CalendarItem x:Name="PART_CalendarItem" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Style="{DynamicResource MaterialDesignCalendarItemPortrait}"/>
- </Border>
- </AdornerDecorator>
+ </Border>
+ </AdornerDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -47,11 +47,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuBase}">
- <AdornerDecorator>
- <!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}"
Effect="{DynamicResource MaterialDesignShadowDepth1}"
Margin="3"
@@ -176,11 +172,8 @@
Focusable="False"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="Slide"
- Placement="Bottom">
- <!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
- <Popup.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </Popup.CacheMode>
+ Placement="Bottom"
+ CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="SubMenuBorder"
Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}"
Effect="{DynamicResource MaterialDesignShadowDepth1}"
@@ -206,10 +206,7 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Ellipse Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"
Effect="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
x:Name="border">
@@ -28,12 +28,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
- <AdornerDecorator>
- <!-- warning, this will cache the inner item as well, consider separating the shadow from the item if possible -->
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
-
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
</Border>
@@ -345,10 +345,7 @@
<ScaleTransform ScaleX="1" ScaleY="1"/>
</Ellipse.RenderTransform>
</Ellipse>
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
- </AdornerDecorator.CacheMode>
+ <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Ellipse x:Name="Thumb"
Fill="#FFFAFAFA" Stroke="{x:Null}"
HorizontalAlignment="Center" VerticalAlignment="Center"
Oops, something went wrong.

0 comments on commit 7a7b828

Please sign in to comment.