Skip to content

Commit ee3b645

Browse files
committed
Add StayOnCenter property
Add StayOnCenter which means that bubble effect raising up from center of control instead of cursor. Also apply StayOnCenter property to toolbar buttons
1 parent bd9b00a commit ee3b645

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

MaterialDesignThemes.Wpf/Ripple.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,35 @@ public Ripple()
3737

3838
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
3939
{
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;
4343

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+
4557
RippleSize = 2 * radius * RippleSizeMultiplier;
4658
}
4759

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+
4869
public static readonly DependencyProperty FeedbackProperty = DependencyProperty.Register(
4970
"Feedback", typeof(Brush), typeof(Ripple), new PropertyMetadata(default(Brush)));
5071

@@ -58,8 +79,16 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
5879
{
5980
var point = e.GetPosition(this);
6081

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+
}
6392

6493
base.OnPreviewMouseLeftButtonDown(e);
6594
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RatingBar.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
3636
Padding="{TemplateBinding Padding}"
3737
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
38+
StayOnCenter="True"
3839
RenderTransformOrigin=".5, .5">
3940
<wpf:Ripple.RenderTransform>
4041
<RotateTransform x:Name="RotateTransform"></RotateTransform>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ToolBar.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
<Setter.Value>
228228
<ControlTemplate TargetType="{x:Type Button}">
229229
<wpf:Ripple Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Focusable="False"
230+
StayOnCenter="True"
230231
x:Name="RippleWrapper"
231232
Feedback="{TemplateBinding Foreground}"
232233
ClipToBounds="False"

0 commit comments

Comments
 (0)