Skip to content

Commit

Permalink
Refine shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Mar 27, 2020
1 parent 32c64f1 commit 7fc8d4c
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 74 deletions.
1 change: 0 additions & 1 deletion ModernWpf.Controls/AutoSuggestBox/AutoSuggestBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
IsOpen="{Binding IsSuggestionListOpen, RelativeSource={RelativeSource TemplatedParent}}">
<ui:ThemeShadowChrome
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{Binding ElementName=SuggestionsContainer, Path=CornerRadius}"
Width="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxSuggestionListHeight}">
<Border
Expand Down
1 change: 0 additions & 1 deletion ModernWpf.Controls/CommandBar/CommandBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
<ui:ThemeShadowChrome
x:Name="OverflowContentRoot"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{Binding ElementName=SecondaryItemsControl, Path=CornerRadius}"
MinWidth="{DynamicResource CommandBarOverflowMinWidth}"
MaxWidth="{DynamicResource CommandBarOverflowMaxWidth}"
MaxHeight="{TemplateBinding OverflowContentMaxHeight}"
Expand Down
3 changes: 1 addition & 2 deletions ModernWpf.Controls/ContentDialog/ContentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@
<ui:ThemeShadowChrome
x:Name="Shdw"
IsShadowEnabled="{TemplateBinding IsShadowEnabled}"
Margin="{DynamicResource ContentDialogBorderWidth}"
CornerRadius="{TemplateBinding CornerRadius}" />
Margin="{DynamicResource ContentDialogBorderWidth}" />
<Border
Background="{TemplateBinding Background}"
BorderThickness="{DynamicResource ContentDialogBorderWidth}"
Expand Down
1 change: 0 additions & 1 deletion ModernWpf.Controls/Flyout/FlyoutPresenter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<ControlTemplate TargetType="local:FlyoutPresenter">
<ui:ThemeShadowChrome
IsShadowEnabled="{TemplateBinding IsDefaultShadowEnabled}"
CornerRadius="{TemplateBinding CornerRadius}"
SnapsToDevicePixels="True">
<Border
x:Name="LayoutRoot"
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf.Controls/ModernWpf.Controls.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net45</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net45;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<NeutralLanguage>en-US</NeutralLanguage>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetDocumentationFile</TargetsForTfmSpecificBuildOutput>
Expand Down
4 changes: 4 additions & 0 deletions ModernWpf.Controls/ModernWpfUI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<dependency id="System.Runtime.WindowsRuntime" version="4.7.0" exclude="Build,Analyzers" />
<dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETFramework4.6.2">
<dependency id="System.Runtime.WindowsRuntime" version="4.7.0" exclude="Build,Analyzers" />
<dependency id="System.ValueTuple" version="4.5.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETCoreApp3.0">
<dependency id="System.Runtime.WindowsRuntime" version="4.7.0" exclude="Build,Analyzers" />
</group>
Expand Down
1 change: 0 additions & 1 deletion ModernWpf.Controls/NumberBox/NumberBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@
HorizontalOffset="{DynamicResource NumberBoxPopupHorizonalOffset}"
HorizontalAlignment="Left">
<ui:ThemeShadowChrome
CornerRadius="{DynamicResource OverlayCornerRadius}"
Depth="{DynamicResource NumberBoxPopupShadowDepth}"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
<Border
Expand Down
2 changes: 1 addition & 1 deletion ModernWpf.MahApps/ModernWpf.MahApps.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>net452;net46;net47;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net452;net46;net462;net47;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<UseWPF>true</UseWPF>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
3 changes: 1 addition & 2 deletions ModernWpf.MahApps/Themes/SimpleTimePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@
StaysOpen="False">
<ui:ThemeShadowChrome
MinWidth="{Binding ActualWidth, ElementName=PART_Button}"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{DynamicResource OverlayCornerRadius}">
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
<Border
x:Name="Background"
Background="{DynamicResource TimePickerFlyoutPresenterBackground}"
Expand Down
46 changes: 46 additions & 0 deletions ModernWpf.SampleApp/ControlPages/ShadowPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Page
x:Class="ModernWpf.SampleApp.ControlPages.ShadowPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
mc:Ignorable="d">

<ui:SimpleStackPanel Margin="{StaticResource ControlPageContentMargin}">
<sc:ControlExample
HeaderText="ThemeShadowChrome"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<Border Background="{DynamicResource SystemControlBackgroundAltHighBrush}"
Padding="96"
ui:ThemeManager.RequestedTheme="Light">
<ui:ThemeShadowChrome
IsShadowEnabled="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Depth="{Binding ElementName=DepthSlider, Path=Value}">
<Rectangle
Width="200"
Height="200"
Fill="{DynamicResource SystemControlBackgroundAltHighBrush}" />
</ui:ThemeShadowChrome>
</Border>

<sc:ControlExample.Options>
<ui:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
<Slider
x:Name="DepthSlider"
ui:ControlHelper.Header="Depth"
Ticks="1,2,3,4,6,8,9,12,16,24,32,40,48,64,80,96"
IsSnapToTickEnabled="True"
Minimum="1"
Maximum="96"
Value="32"
AutoToolTipPlacement="TopLeft" />
</ui:SimpleStackPanel>
</sc:ControlExample.Options>
</sc:ControlExample>
</ui:SimpleStackPanel>
</Page>
26 changes: 26 additions & 0 deletions ModernWpf.SampleApp/ControlPages/ShadowPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ModernWpf.SampleApp.ControlPages
{
/// <summary>
/// Interaction logic for ShadowPage.xaml
/// </summary>
public partial class ShadowPage : Page
{
public ShadowPage()
{
InitializeComponent();
}
}
}
2 changes: 1 addition & 1 deletion ModernWpf.SampleApp/ModernWpf.SampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>netcoreapp3.1;net45</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net45;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
Expand Down
1 change: 1 addition & 0 deletions ModernWpf.SampleApp/Navigation/NavigationRootPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public ControlPagesData()
AddPage(typeof(RadioButtonsPage));
AddPage(typeof(RatingControlPage));
AddPage(typeof(RichTextBoxPage));
AddPage(typeof(ShadowPage));
AddPage(typeof(SimpleStackPanelPage));
AddPage(typeof(SliderPage));
//AddPage(typeof(StatusBarPage));
Expand Down
90 changes: 42 additions & 48 deletions ModernWpf/Controls/Primitives/ThemeShadowChrome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Shapes;

namespace ModernWpf.Controls.Primitives
{
Expand All @@ -22,19 +23,18 @@ static ThemeShadowChrome()
s_bg2.Freeze();
s_bg3.Freeze();
s_bg4.Freeze();

s_bitmapCache = new BitmapCache
{
SnapsToDevicePixels = false
};
s_bitmapCache.Freeze();
}

public ThemeShadowChrome()
{
#if NETCOREAPP || NET462
_bitmapCache = new BitmapCache(VisualTreeHelper.GetDpi(this).PixelsPerDip);
#else
_bitmapCache = new BitmapCache();
#endif
_background = new Grid
{
CacheMode = s_bitmapCache,
CacheMode = _bitmapCache,
SnapsToDevicePixels = false
};
AddVisualChild(_background);
Expand Down Expand Up @@ -122,39 +122,21 @@ private void OnDepthChanged()

#region CornerRadius

[Obsolete]
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register(
nameof(CornerRadius),
typeof(CornerRadius),
typeof(ThemeShadowChrome),
new PropertyMetadata(new CornerRadius(), OnCornerRadiusChanged));
new PropertyMetadata(new CornerRadius()));

[Obsolete]
public CornerRadius CornerRadius
{
get => (CornerRadius)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}

private static void OnCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ThemeShadowChrome)d).OnCornerRadiusChanged(e);
}

private void OnCornerRadiusChanged(DependencyPropertyChangedEventArgs e)
{
var cornerRadius = (CornerRadius)e.NewValue;

if (_shadow1 != null)
{
_shadow1.CornerRadius = cornerRadius;
}

if (_shadow2 != null)
{
_shadow2.CornerRadius = cornerRadius;
}
}

#endregion

#region PopupMargin
Expand Down Expand Up @@ -280,6 +262,15 @@ protected override Size ArrangeOverride(Size arrangeSize)
return base.ArrangeOverride(arrangeSize);
}

#if NETCOREAPP || NET462
protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)
{
base.OnDpiChanged(oldDpi, newDpi);

_bitmapCache.RenderAtScale = newDpi.PixelsPerDip;
}
#endif

private void OnVisualParentChanged()
{
if (IsShadowEnabled)
Expand Down Expand Up @@ -323,17 +314,12 @@ private void EnsureShadows()
}
}

private Border CreateShadowElement()
private Rectangle CreateShadowElement()
{
return new Border
return new Rectangle
{
Background = Brushes.Black,
CornerRadius = CornerRadius,
Effect = new DropShadowEffect
{
Direction = 270,
Color = Colors.Black
}
Effect = new BlurEffect(),
RenderTransform = new TranslateTransform()
};
}

Expand All @@ -342,10 +328,14 @@ private void UpdateShadow1()
if (_shadow1 != null)
{
double depth = Depth;
var effect = (DropShadowEffect)_shadow1.Effect;
effect.ShadowDepth = 0.4 * depth;
effect.BlurRadius = 0.9 * depth;
_shadow1.Background = depth >= 32 ? s_bg4 : s_bg3;

var effect = (BlurEffect)_shadow1.Effect;
effect.Radius = 0.9 * depth;

var transform = (TranslateTransform)_shadow1.RenderTransform;
transform.Y = 0.4 * depth;

_shadow1.Fill = depth >= 32 ? s_bg4 : s_bg2;
}
}

Expand All @@ -354,10 +344,14 @@ private void UpdateShadow2()
if (_shadow2 != null)
{
double depth = Depth;
var effect = (DropShadowEffect)_shadow2.Effect;
effect.ShadowDepth = 0.08 * depth;
effect.BlurRadius = 0.22 * depth;
_shadow2.Background = depth >= 32 ? s_bg2 : s_bg1;

var effect = (BlurEffect)_shadow2.Effect;
effect.Radius = 0.225 * depth;

var transform = (TranslateTransform)_shadow2.RenderTransform;
transform.Y = 0.075 * depth;

_shadow2.Fill = depth >= 32 ? s_bg3 : s_bg1;
}
}

Expand Down Expand Up @@ -830,13 +824,13 @@ private void OnClosed(object sender, EventArgs e)
}

private readonly Grid _background;
private Border _shadow1;
private Border _shadow2;
private readonly BitmapCache _bitmapCache;
private Rectangle _shadow1;
private Rectangle _shadow2;
private PopupControl _parentPopupControl;
private TranslateTransform _transform;

private static readonly Brush s_bg1, s_bg2, s_bg3, s_bg4;
private static readonly BitmapCache s_bitmapCache;
private static readonly Vector s_noTranslation = new Vector(0, 0);
}
}
2 changes: 1 addition & 1 deletion ModernWpf/Helpers/DispatcherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if NET45
#if !NETCOREAPP
using System;
using System.ComponentModel; // EditorBrowsableAttribute, BrowsableAttribute

Expand Down
2 changes: 1 addition & 1 deletion ModernWpf/ModernWpf.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net45</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net45;net462</TargetFrameworks>
<UseWPF>true</UseWPF>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
1 change: 0 additions & 1 deletion ModernWpf/Styles/Calendar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@
<primitives:ThemeShadowChrome
x:Name="Shdw"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
SnapsToDevicePixels="True"
primitives:OpeningAnimationHelper.Storyboard="{DynamicResource OpeningStoryboard}">
<primitives:ThemeShadowChrome.Resources>
Expand Down
1 change: 0 additions & 1 deletion ModernWpf/Styles/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=LayoutRoot}"
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{Binding ElementName=PopupBorder, Path=CornerRadius}"
primitives:OpeningAnimationHelper.Storyboard="{StaticResource OverlayOpeningAnimation}">
<Border
x:Name="PopupBorder"
Expand Down
8 changes: 2 additions & 6 deletions ModernWpf/Styles/MenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
Placement="Bottom">
<primitives:ThemeShadowChrome
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{DynamicResource OverlayCornerRadius}">
<primitives:ThemeShadowChrome IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
<Border
x:Name="SubMenuRoot"
Background="{DynamicResource MenuFlyoutPresenterBackground}"
Expand Down Expand Up @@ -313,9 +311,7 @@
<Binding ElementName="LayoutRoot" Path="ActualHeight" />
</MultiBinding>
</Popup.PlacementRectangle>
<primitives:ThemeShadowChrome
IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
CornerRadius="{DynamicResource OverlayCornerRadius}">
<primitives:ThemeShadowChrome IsShadowEnabled="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
<Border
x:Name="SubMenuRoot"
Background="{DynamicResource MenuFlyoutPresenterBackground}"
Expand Down
Loading

0 comments on commit 7fc8d4c

Please sign in to comment.