@@ -37,14 +37,35 @@ public Ripple()
37
37
38
38
private void OnSizeChanged ( object sender , SizeChangedEventArgs sizeChangedEventArgs )
39
39
{
40
- double width = sizeChangedEventArgs . NewSize . Width ;
41
- double height = sizeChangedEventArgs . NewSize . Height ;
42
- double radius = Math . Sqrt ( Math . Pow ( width , 2 ) + Math . Pow ( height , 2 ) ) ;
40
+ var innerContent = ( Content as FrameworkElement ) ;
41
+
42
+ double width , height ;
43
43
44
- Debug . WriteLine ( "Width: {0} Height: {1} Radius: {2}" , width , height , radius ) ;
44
+ if ( innerContent != null )
45
+ {
46
+ width = innerContent . ActualWidth ;
47
+ height = innerContent . ActualHeight ;
48
+ }
49
+ else
50
+ {
51
+ width = sizeChangedEventArgs . NewSize . Width ;
52
+ height = sizeChangedEventArgs . NewSize . Height ;
53
+ }
54
+
55
+ double radius = Math . Sqrt ( Math . Pow ( width , 2 ) + Math . Pow ( height , 2 ) ) ;
56
+
45
57
RippleSize = 2 * radius * RippleSizeMultiplier ;
46
58
}
47
59
60
+ public static readonly DependencyProperty StayOnCenterProperty = DependencyProperty . Register (
61
+ "StayOnCenter" , typeof ( bool ) , typeof ( Ripple ) , new PropertyMetadata ( false ) ) ;
62
+
63
+ public bool StayOnCenter
64
+ {
65
+ get { return ( bool ) GetValue ( StayOnCenterProperty ) ; }
66
+ set { SetValue ( StayOnCenterProperty , value ) ; }
67
+ }
68
+
48
69
public static readonly DependencyProperty FeedbackProperty = DependencyProperty . Register (
49
70
"Feedback" , typeof ( Brush ) , typeof ( Ripple ) , new PropertyMetadata ( default ( Brush ) ) ) ;
50
71
@@ -58,8 +79,16 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
58
79
{
59
80
var point = e . GetPosition ( this ) ;
60
81
61
- RippleX = point . X - RippleSize / 2 ;
62
- RippleY = point . Y - RippleSize / 2 ;
82
+ if ( StayOnCenter )
83
+ {
84
+ RippleX = this . ActualWidth / 2 - RippleSize / 2 ;
85
+ RippleY = this . ActualHeight / 2 - RippleSize / 2 ;
86
+ }
87
+ else
88
+ {
89
+ RippleX = point . X - RippleSize / 2 ;
90
+ RippleY = point . Y - RippleSize / 2 ;
91
+ }
63
92
64
93
base . OnPreviewMouseLeftButtonDown ( e ) ;
65
94
}
0 commit comments