Skip to content

Commit 57acafb

Browse files
committed
few more ripple tweaks...get rid of IsActive
1 parent 227e2e4 commit 57acafb

File tree

7 files changed

+41
-58
lines changed

7 files changed

+41
-58
lines changed

MainDemo.Wpf/Cards.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</StackPanel>
4141
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Margin="8">
4242
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0"
43-
wpf:RippleAssist.StayOnCenter="True">
43+
wpf:RippleAssist.IsCentered="True">
4444
<Viewbox Width="16" Height="16">
4545
<Canvas Width="24" Height="24">
4646
<Path Data="M18,16.08C17.24,16.08 16.56,16.38 16.04,16.85L8.91,12.7C8.96,12.47 9,12.24 9,12C9,11.76 8.96,11.53 8.91,11.3L15.96,7.19C16.5,7.69 17.21,8 18,8A3,3 0 0,0 21,5A3,3 0 0,0 18,2A3,3 0 0,0 15,5C15,5.24 15.04,5.47 15.09,5.7L8.04,9.81C7.5,9.31 6.79,9 6,9A3,3 0 0,0 3,12A3,3 0 0,0 6,15C6.79,15 7.5,14.69 8.04,14.19L15.16,18.34C15.11,18.55 15.08,18.77 15.08,19C15.08,20.61 16.39,21.91 18,21.91C19.61,21.91 20.92,20.61 20.92,19A2.92,2.92 0 0,0 18,16.08Z"
@@ -49,7 +49,7 @@
4949
</Viewbox>
5050
</Button>
5151
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0"
52-
wpf:RippleAssist.StayOnCenter="True">
52+
wpf:RippleAssist.IsCentered="True">
5353
<Viewbox Width="16" Height="16">
5454
<Canvas Width="24" Height="24">
5555
<Path Data="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"

MainDemo.Wpf/ColorZones.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<TextBlock VerticalAlignment="Center" Margin="16 0 0 0">Material Design In XAML Toolkit</TextBlock>
2020
</StackPanel>
2121
<Button Style="{DynamicResource MaterialDesignToolForegroundButton}" DockPanel.Dock="Right" HorizontalAlignment="Right"
22-
wpf:RippleAssist.StayOnCenter="True">
22+
wpf:RippleAssist.IsCentered="True">
2323
<Viewbox Width="16" Height="16">
2424
<Canvas Width="24" Height="24">
2525
<Path Data="M2,21L23,12L2,3V10L17,12L2,14V21Z" Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}" />
@@ -38,7 +38,7 @@
3838
<TextBlock Margin="0 16 0 0" FontSize="10">Use primary mid colours, and nest colour zones!</TextBlock>
3939
<wpf:ColorZone Mode="PrimaryMid" Padding="16">
4040
<StackPanel Orientation="Horizontal"
41-
wpf:RippleAssist.StayOnCenter="True">
41+
wpf:RippleAssist.IsCentered="True">
4242
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
4343
<wpf:ColorZone Mode="Standard" Padding="8 4 8 4" CornerRadius="2" Panel.ZIndex="1"
4444
Margin="16 0 0 0"

MaterialDesignThemes.Wpf/Ripple.cs

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@ public class Ripple : ContentControl
2626
public const string TemplateStateNormal = "Normal";
2727
public const string TemplateStateMousePressed = "MousePressed";
2828

29+
private static readonly HashSet<Ripple> LoadedInstances = new HashSet<Ripple>();
30+
2931
static Ripple()
30-
{
32+
{
3133
DefaultStyleKeyProperty.OverrideMetadata(typeof(Ripple), new FrameworkPropertyMetadata(typeof(Ripple)));
34+
35+
EventManager.RegisterClassHandler(typeof(Window), Mouse.PreviewMouseUpEvent, new MouseButtonEventHandler(MouseButtonEventHandler), true);
3236
}
3337

3438
public Ripple()
35-
{
39+
{
3640
SizeChanged += OnSizeChanged;
41+
42+
Loaded += (sender, args) => LoadedInstances.Add((Ripple) sender);
43+
Unloaded += (sender, args) => LoadedInstances.Remove((Ripple)sender);
44+
}
45+
46+
private static void MouseButtonEventHandler(object sender, MouseButtonEventArgs e)
47+
{
48+
foreach (var loadedInstance in LoadedInstances)
49+
VisualStateManager.GoToState(loadedInstance, TemplateStateNormal, false);
3750
}
3851

3952
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
@@ -42,7 +55,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventA
4255

4356
double width, height;
4457

45-
if (RippleAssist.GetStayOnCenter(this) && innerContent != null)
58+
if (RippleAssist.GetIsCentered(this) && innerContent != null)
4659
{
4760
width = innerContent.ActualWidth;
4861
height = innerContent.ActualHeight;
@@ -53,7 +66,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventA
5366
height = sizeChangedEventArgs.NewSize.Height;
5467
}
5568

56-
double radius = Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2));
69+
var radius = Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2));
5770

5871
RippleSize = 2 * radius * RippleAssist.GetRippleSizeMultiplier(this);
5972
}
@@ -71,13 +84,13 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
7184
{
7285
var point = e.GetPosition(this);
7386

74-
if (RippleAssist.GetStayOnCenter(this))
87+
if (RippleAssist.GetIsCentered(this))
7588
{
7689
var innerContent = (Content as FrameworkElement);
7790

7891
if (innerContent != null)
7992
{
80-
Point position = innerContent.TransformToAncestor(this)
93+
var position = innerContent.TransformToAncestor(this)
8194
.Transform(new Point(0, 0));
8295

8396
RippleX = position.X + innerContent.ActualWidth / 2 - RippleSize / 2;
@@ -94,7 +107,9 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
94107
RippleX = point.X - RippleSize / 2;
95108
RippleY = point.Y - RippleSize / 2;
96109
}
97-
110+
111+
VisualStateManager.GoToState(this, TemplateStateMousePressed, true);
112+
98113
base.OnPreviewMouseLeftButtonDown(e);
99114
}
100115

@@ -138,44 +153,12 @@ public double RippleY
138153
{
139154
get { return (double)GetValue(RippleYProperty); }
140155
private set { SetValue(RippleYPropertyKey, value); }
141-
}
142-
143-
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(
144-
"IsActive", typeof(bool), typeof(Ripple), new FrameworkPropertyMetadata(false, IsActivePropertyChangedCallback));
145-
146-
public bool IsActive
147-
{
148-
get { return (bool)GetValue(IsActiveProperty); }
149-
set { SetValue(IsActiveProperty, value); }
150-
}
151-
152-
private static void IsActivePropertyChangedCallback(
153-
DependencyObject dependencyObject,
154-
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
155-
{
156-
var box = dependencyObject as Ripple;
157-
if (box == null) return;
158-
159-
bool isActive = (bool)dependencyPropertyChangedEventArgs.NewValue;
160-
161-
VisualStateManager.GoToState(box, isActive ? TemplateStateMousePressed : TemplateStateNormal, true);
162-
}
156+
}
163157

164158
public override void OnApplyTemplate()
165159
{
166160
base.OnApplyTemplate();
167-
168-
var button = (TemplatedParent as ButtonBase);
169-
if (button != null)
170-
{
171-
Binding isPressedBinding = new Binding
172-
{
173-
Path = new PropertyPath("IsPressed"),
174-
Source = button
175-
};
176-
this.SetBinding(Ripple.IsActiveProperty, isPressedBinding);
177-
}
178-
161+
179162
VisualStateManager.GoToState(this, TemplateStateNormal, false);
180163
}
181164
}

MaterialDesignThemes.Wpf/RippleAssist.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public static bool GetClipToBounds(DependencyObject element)
2323

2424
#region StayOnCenter
2525

26-
public static readonly DependencyProperty StayOnCenterProperty = DependencyProperty.RegisterAttached(
27-
"StayOnCenter", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
26+
public static readonly DependencyProperty IsCenteredProperty = DependencyProperty.RegisterAttached(
27+
"IsCentered", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
2828

29-
public static void SetStayOnCenter(DependencyObject element, bool value)
29+
public static void SetIsCentered(DependencyObject element, bool value)
3030
{
31-
element.SetValue(StayOnCenterProperty, value);
31+
element.SetValue(IsCenteredProperty, value);
3232
}
3333

34-
public static bool GetStayOnCenter(DependencyObject element)
34+
public static bool GetIsCentered(DependencyObject element)
3535
{
36-
return (bool)element.GetValue(StayOnCenterProperty);
36+
return (bool)element.GetValue(IsCenteredProperty);
3737
}
3838

3939
#endregion

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@
4343
<Storyboard>
4444
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleX" Storyboard.TargetName="ScaleTransform">
4545
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
46-
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1">
46+
<EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="1">
4747
<EasingDoubleKeyFrame.EasingFunction>
48-
<SineEase EasingMode="EaseInOut" />
48+
<SineEase EasingMode="EaseIn" />
4949
</EasingDoubleKeyFrame.EasingFunction>
5050
</EasingDoubleKeyFrame>
5151
</DoubleAnimationUsingKeyFrames>
5252
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="ScaleY" Storyboard.TargetName="ScaleTransform">
5353
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
54-
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="1">
54+
<EasingDoubleKeyFrame KeyTime="0:0:2.2" Value="1">
5555
<EasingDoubleKeyFrame.EasingFunction>
56-
<SineEase EasingMode="EaseInOut" />
56+
<SineEase EasingMode="EaseIn" />
5757
</EasingDoubleKeyFrame.EasingFunction>
5858
</EasingDoubleKeyFrame>
5959
</DoubleAnimationUsingKeyFrames>
6060
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ClickEllipse">
6161
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
6262
<EasingDoubleKeyFrame KeyTime="0:0:0.05" Value=".26"/>
63-
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value=".26"/>
63+
<EasingDoubleKeyFrame KeyTime="0:0:2.2" Value=".26"/>
6464
</DoubleAnimationUsingKeyFrames>
6565
</Storyboard>
6666
</VisualTransition>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RatingBar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<Setter Property="Command" Value="{x:Static wpf:RatingBar.SelectRatingCommand}"/>
2626
<Setter Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Self}, Path=Value}"/>
2727
<Setter Property="wpf:RippleAssist.ClipToBounds" Value="False"/>
28-
<Setter Property="wpf:RippleAssist.StayOnCenter" Value="True"/>
28+
<Setter Property="wpf:RippleAssist.IsCentered" Value="True"/>
2929
<Setter Property="wpf:RippleAssist.RippleSizeMultiplier" Value="0.5"/>
3030
<Setter Property="Template">
3131
<Setter.Value>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ToolBar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
<Setter Property="VerticalContentAlignment" Value="Center"/>
224224
<Setter Property="TextBlock.FontWeight" Value="DemiBold"/>
225225
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}"/>
226-
<Setter Property="wpf:RippleAssist.StayOnCenter" Value="True"/>
226+
<Setter Property="wpf:RippleAssist.IsCentered" Value="True"/>
227227
<Setter Property="Template">
228228
<Setter.Value>
229229
<ControlTemplate TargetType="{x:Type Button}">

0 commit comments

Comments
 (0)