1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Effects;
namespace MaterialDesignThemes.Wpf.Converters
{
public class ShadowEdgeConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values?.Length != 4)
{
return Binding.DoNothing;
}
if (!(values[0] is double) || !(values[1] is double) || !(values[2] is ShadowDepth) ||
!(values[3] is ShadowEdges))
{
return Binding.DoNothing;
}
double width = (double)values[0];
double height = (double)values[1];
if (double.IsNaN(width) || double.IsInfinity(width) || double.IsNaN(height) || double.IsInfinity(height))
{
return Binding.DoNothing;
}
DropShadowEffect dropShadow = ShadowInfo.GetDropShadow((ShadowDepth)values[2]);
if (dropShadow == null)
{
return Binding.DoNothing;
}
ShadowEdges edges = (ShadowEdges)values[3];
double blurRadius = dropShadow.BlurRadius;
var rect = new Rect(0, 0, width, height);
if (edges.HasFlag(ShadowEdges.Left))
{
rect = new Rect(rect.X - blurRadius, rect.Y, rect.Width + blurRadius, rect.Height);
}
if (edges.HasFlag(ShadowEdges.Top))
{
rect = new Rect(rect.X, rect.Y - blurRadius, rect.Width, rect.Height + blurRadius);
}
if (edges.HasFlag(ShadowEdges.Right))
{
rect = new Rect(rect.X, rect.Y, rect.Width + blurRadius, rect.Height);
}
if (edges.HasFlag(ShadowEdges.Bottom))
{
rect = new Rect(rect.X, rect.Y, rect.Width, rect.Height + blurRadius);
}
var size = new GeometryDrawing(new SolidColorBrush(Colors.White), new Pen(), new RectangleGeometry(rect));
return new DrawingBrush(size)
{
Stretch = Stretch.None,
TileMode = TileMode.None,
Viewport = rect,
ViewportUnits = BrushMappingMode.Absolute,
Viewbox = rect,
ViewboxUnits = BrushMappingMode.Absolute
};
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
|