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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.Devices.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
namespace MaterialDesignThemes.Uwp
{
[TemplateVisualState(GroupName = "CommonStates", Name = "Normal")]
[TemplateVisualState(GroupName = "CommonStates", Name = "Pressed")]
public sealed class Ripple : ContentControl, INotifyPropertyChanged
{
private double _rippleSize;
private double _rippleX;
private double _rippleY;
public Ripple()
{
DefaultStyleKey = typeof(Ripple);
SizeChanged += OnSizeChanged;
}
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
{
RippleSize = Math.Max(sizeChangedEventArgs.NewSize.Width, sizeChangedEventArgs.NewSize.Height) * RippleSizeMultiplier;
Clip = new RectangleGeometry { Rect = new Windows.Foundation.Rect(0, 0, sizeChangedEventArgs.NewSize.Width, sizeChangedEventArgs.NewSize.Height) };
}
public static readonly DependencyProperty FeedbackProperty = DependencyProperty.Register(
"Feedback", typeof (Brush), typeof (Ripple), new PropertyMetadata(default(Brush)));
public Brush Feedback
{
get { return (Brush) GetValue(FeedbackProperty); }
set { SetValue(FeedbackProperty, value); }
}
protected override void OnApplyTemplate()
{
VisualStateManager.GoToState(this, "Normal", false);
base.OnApplyTemplate();
}
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
var point = e.GetCurrentPoint(this);
RippleX = point.Position.X - RippleSize/2;
RippleY = point.Position.Y - RippleSize/2;
VisualStateManager.GoToState(this, "Normal", true);
VisualStateManager.GoToState(this, "MousePressed", true);
}
base.OnPointerPressed(e);
}
public static readonly DependencyProperty RippleSizeMultiplierProperty = DependencyProperty.Register(
"RippleSizeMultiplier", typeof (double), typeof (Ripple), new PropertyMetadata(1.75));
public double RippleSizeMultiplier
{
get { return (double) GetValue(RippleSizeMultiplierProperty); }
set { SetValue(RippleSizeMultiplierProperty, value); }
}
public double RippleSize
{
get { return _rippleSize; }
private set
{
if (_rippleSize == value) return;
_rippleSize = value;
OnPropertyChanged();
}
}
public double RippleY
{
get { return _rippleY; }
private set
{
if (_rippleY == value) return;
_rippleY = value;
OnPropertyChanged();
}
}
public double RippleX
{
get { return _rippleX; }
private set
{
if (_rippleX == value) return;
_rippleX = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
|