Skip to content

Commit d01f32d

Browse files
committed
merge stuff
2 parents 7c5c509 + c6599a2 commit d01f32d

18 files changed

+555
-266
lines changed

MainDemo.Wpf/Cards.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@
3939
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center">A great way to keep fit and forget about the constant grind of IT.</TextBlock>
4040
</StackPanel>
4141
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Margin="8">
42-
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0">
42+
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0"
43+
wpf:RippleAssist.IsCentered="True">
4344
<Viewbox Width="16" Height="16">
4445
<Canvas Width="24" Height="24">
4546
<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"
4647
Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=Foreground}" />
4748
</Canvas>
4849
</Viewbox>
4950
</Button>
50-
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0">
51+
<Button Style="{StaticResource MaterialDesignToolButton}" Width="30" Padding="2 0 2 0"
52+
wpf:RippleAssist.IsCentered="True">
5153
<Viewbox Width="16" Height="16">
5254
<Canvas Width="24" Height="24">
5355
<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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:local="clr-namespace:MaterialDesignColors.WpfExample"
77
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
88
mc:Ignorable="d"
9-
d:DesignHeight="300" d:DesignWidth="300">
9+
d:DesignHeight="800" d:DesignWidth="600">
1010
<ScrollViewer>
1111
<StackPanel Margin="16">
1212
<TextBlock FontSize="16">Colour Zones</TextBlock>
@@ -18,7 +18,8 @@
1818
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
1919
<TextBlock VerticalAlignment="Center" Margin="16 0 0 0">Material Design In XAML Toolkit</TextBlock>
2020
</StackPanel>
21-
<Button Style="{DynamicResource MaterialDesignToolForegroundButton}" DockPanel.Dock="Right" HorizontalAlignment="Right">
21+
<Button Style="{DynamicResource MaterialDesignToolForegroundButton}" DockPanel.Dock="Right" HorizontalAlignment="Right"
22+
wpf:RippleAssist.IsCentered="True">
2223
<Viewbox Width="16" Height="16">
2324
<Canvas Width="24" Height="24">
2425
<Path Data="M2,21L23,12L2,3V10L17,12L2,14V21Z" Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}" />
@@ -36,7 +37,8 @@
3637
</wpf:ColorZone>
3738
<TextBlock Margin="0 16 0 0" FontSize="10">Use primary mid colours, and nest colour zones!</TextBlock>
3839
<wpf:ColorZone Mode="PrimaryMid" Padding="16">
39-
<StackPanel Orientation="Horizontal">
40+
<StackPanel Orientation="Horizontal"
41+
wpf:RippleAssist.IsCentered="True">
4042
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
4143
<wpf:ColorZone Mode="Standard" Padding="8 4 8 4" CornerRadius="2" Panel.ZIndex="1"
4244
Margin="16 0 0 0"

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public MainWindow()
1111
{
1212
InitializeComponent();
1313
}
14-
}
14+
}
1515
}

MaterialDesignThemes.Wpf/Clock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private void ClockItemDragDeltaHandler(object sender, DragDeltaEventArgs dragDel
269269
if (angle < 0) angle += 2 * Math.PI;
270270

271271
var time = DisplayMode == ClockDisplayMode.Hours
272-
? new DateTime(Time.Year, Time.Month, Time.Day, (int)Math.Round(6 * angle / Math.PI, MidpointRounding.AwayFromZero) % 12, Time.Minute, Time.Second)
272+
? new DateTime(Time.Year, Time.Month, Time.Day, (int)Math.Round(6 * angle / Math.PI, MidpointRounding.AwayFromZero) % 12 + (IsPostMeridiem? 12 : 0), Time.Minute, Time.Second)
273273
: new DateTime(Time.Year, Time.Month, Time.Day, Time.Hour, (int)Math.Round(30 * angle / Math.PI, MidpointRounding.AwayFromZero) % 60, Time.Second);
274274

275275
SetCurrentValue(TimeProperty, time);

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
<Compile Include="DialogClosingEventArgs.cs" />
222222
<Compile Include="DialogClosingEventHandler.cs" />
223223
<Compile Include="DialogHost.cs" />
224-
<Compile Include="Extensions.cs" />
225224
<Compile Include="ListSortDirectionIndicator.cs" />
226225
<Compile Include="MaterialDataGridComboBoxColumn.cs" />
227226
<Compile Include="MaterialDataGridTextColumn.cs" />
@@ -249,6 +248,7 @@
249248
<Compile Include="ToolTipAssist.cs" />
250249
<Compile Include="RippleAssist.cs" />
251250
<Compile Include="Ripple.cs" />
251+
<Compile Include="Underline.cs" />
252252
<Compile Include="ValidationAssist.cs" />
253253
<EmbeddedResource Include="Properties\Resources.resx">
254254
<Generator>ResXFileCodeGenerator</Generator>

MaterialDesignThemes.Wpf/Ripple.cs

Lines changed: 99 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,61 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
64
using System.Windows;
75
using System.Windows.Controls;
8-
using System.Windows.Data;
9-
using System.Windows.Documents;
106
using System.Windows.Input;
117
using System.Windows.Media;
12-
using System.Windows.Media.Imaging;
13-
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
158

169
namespace MaterialDesignThemes.Wpf
1710
{
18-
[TemplateVisualState(GroupName = "CommonStates", Name = "Normal")]
19-
[TemplateVisualState(GroupName = "CommonStates", Name = "Pressed")]
11+
[TemplateVisualState(GroupName = "CommonStates", Name = TemplateStateNormal)]
12+
[TemplateVisualState(GroupName = "CommonStates", Name = TemplateStateMousePressed)]
13+
[TemplateVisualState(GroupName = "CommonStates", Name = TemplateStateMouseOut)]
2014
public class Ripple : ContentControl
2115
{
16+
public const string TemplateStateNormal = "Normal";
17+
public const string TemplateStateMousePressed = "MousePressed";
18+
public const string TemplateStateMouseOut = "MouseOut";
19+
20+
private static readonly HashSet<Ripple> PressedInstances = new HashSet<Ripple>();
21+
2222
static Ripple()
23-
{
23+
{
2424
DefaultStyleKeyProperty.OverrideMetadata(typeof(Ripple), new FrameworkPropertyMetadata(typeof(Ripple)));
25+
26+
EventManager.RegisterClassHandler(typeof(Window), Mouse.PreviewMouseUpEvent, new MouseButtonEventHandler(MouseButtonEventHandler), true);
27+
EventManager.RegisterClassHandler(typeof (Window), Mouse.MouseMoveEvent, new MouseEventHandler(MouseMouveEventHandler), true);
2528
}
2629

2730
public Ripple()
28-
{
29-
SizeChanged += OnSizeChanged;
30-
}
31+
{
32+
SizeChanged += OnSizeChanged;
33+
}
3134

32-
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
35+
private static void MouseButtonEventHandler(object sender, MouseButtonEventArgs e)
3336
{
34-
RippleSize = Math.Max(sizeChangedEventArgs.NewSize.Width, sizeChangedEventArgs.NewSize.Height) * RippleSizeMultiplier;
37+
foreach (var ripple in PressedInstances)
38+
VisualStateManager.GoToState(ripple, TemplateStateNormal, false);
39+
PressedInstances.Clear();
3540
}
3641

42+
private static void MouseMouveEventHandler(object sender, MouseEventArgs e)
43+
{
44+
foreach (var ripple in PressedInstances.ToList())
45+
{
46+
var relativePosition = Mouse.GetPosition(ripple);
47+
if (relativePosition.X < 0
48+
|| relativePosition.Y < 0
49+
|| relativePosition.X >= ripple.ActualWidth
50+
|| relativePosition.Y >= ripple.ActualHeight)
51+
52+
{
53+
VisualStateManager.GoToState(ripple, TemplateStateMouseOut, true);
54+
PressedInstances.Remove(ripple);
55+
}
56+
}
57+
}
58+
3759
public static readonly DependencyProperty FeedbackProperty = DependencyProperty.Register(
3860
"Feedback", typeof(Brush), typeof(Ripple), new PropertyMetadata(default(Brush)));
3961

@@ -46,25 +68,38 @@ public Brush Feedback
4668
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
4769
{
4870
var point = e.GetPosition(this);
49-
50-
RippleX = point.X - RippleSize / 2;
51-
RippleY = point.Y - RippleSize / 2;
52-
53-
VisualStateManager.GoToState(this, "Normal", true);
54-
VisualStateManager.GoToState(this, "MousePressed", true);
71+
72+
if (RippleAssist.GetIsCentered(this))
73+
{
74+
var innerContent = (Content as FrameworkElement);
75+
76+
if (innerContent != null)
77+
{
78+
var position = innerContent.TransformToAncestor(this)
79+
.Transform(new Point(0, 0));
80+
81+
RippleX = position.X + innerContent.ActualWidth / 2 - RippleSize / 2;
82+
RippleY = position.Y + innerContent.ActualHeight / 2 - RippleSize / 2;
83+
}
84+
else
85+
{
86+
RippleX = ActualWidth / 2 - RippleSize / 2;
87+
RippleY = ActualHeight / 2 - RippleSize / 2;
88+
}
89+
}
90+
else
91+
{
92+
RippleX = point.X - RippleSize / 2;
93+
RippleY = point.Y - RippleSize / 2;
94+
}
95+
96+
VisualStateManager.GoToState(this, TemplateStateNormal, false);
97+
VisualStateManager.GoToState(this, TemplateStateMousePressed, true);
98+
PressedInstances.Add(this);
5599

56100
base.OnPreviewMouseLeftButtonDown(e);
57101
}
58102

59-
public static readonly DependencyProperty RippleSizeMultiplierProperty = DependencyProperty.Register(
60-
"RippleSizeMultiplier", typeof(double), typeof(Ripple), new PropertyMetadata(1.75));
61-
62-
public double RippleSizeMultiplier
63-
{
64-
get { return (double)GetValue(RippleSizeMultiplierProperty); }
65-
set { SetValue(RippleSizeMultiplierProperty, value); }
66-
}
67-
68103
private static readonly DependencyPropertyKey RippleSizePropertyKey =
69104
DependencyProperty.RegisterReadOnly(
70105
"RippleSize", typeof(double), typeof(Ripple),
@@ -81,30 +116,59 @@ public double RippleSize
81116

82117
private static readonly DependencyPropertyKey RippleXPropertyKey =
83118
DependencyProperty.RegisterReadOnly(
84-
"RippleX", typeof (double), typeof (Ripple),
119+
"RippleX", typeof(double), typeof(Ripple),
85120
new PropertyMetadata(default(double)));
86121

87122
public static readonly DependencyProperty RippleXProperty =
88123
RippleXPropertyKey.DependencyProperty;
89124

90125
public double RippleX
91126
{
92-
get { return (double) GetValue(RippleXProperty); }
127+
get { return (double)GetValue(RippleXProperty); }
93128
private set { SetValue(RippleXPropertyKey, value); }
94129
}
95130

96131
private static readonly DependencyPropertyKey RippleYPropertyKey =
97132
DependencyProperty.RegisterReadOnly(
98-
"RippleY", typeof (double), typeof (Ripple),
133+
"RippleY", typeof(double), typeof(Ripple),
99134
new PropertyMetadata(default(double)));
100135

101136
public static readonly DependencyProperty RippleYProperty =
102137
RippleYPropertyKey.DependencyProperty;
103138

104139
public double RippleY
105140
{
106-
get { return (double) GetValue(RippleYProperty); }
141+
get { return (double)GetValue(RippleYProperty); }
107142
private set { SetValue(RippleYPropertyKey, value); }
108-
}
143+
}
144+
145+
public override void OnApplyTemplate()
146+
{
147+
base.OnApplyTemplate();
148+
149+
VisualStateManager.GoToState(this, TemplateStateNormal, false);
150+
}
151+
152+
private void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
153+
{
154+
var innerContent = (Content as FrameworkElement);
155+
156+
double width, height;
157+
158+
if (RippleAssist.GetIsCentered(this) && innerContent != null)
159+
{
160+
width = innerContent.ActualWidth;
161+
height = innerContent.ActualHeight;
162+
}
163+
else
164+
{
165+
width = sizeChangedEventArgs.NewSize.Width;
166+
height = sizeChangedEventArgs.NewSize.Height;
167+
}
168+
169+
var radius = Math.Sqrt(Math.Pow(width, 2) + Math.Pow(height, 2));
170+
171+
RippleSize = 2 * radius * RippleAssist.GetRippleSizeMultiplier(this);
172+
}
109173
}
110174
}

MaterialDesignThemes.Wpf/RippleAssist.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace MaterialDesignThemes.Wpf
44
{
55
public static class RippleAssist
66
{
7+
#region ClipToBound
8+
79
public static readonly DependencyProperty ClipToBoundsProperty = DependencyProperty.RegisterAttached(
810
"ClipToBounds", typeof (bool), typeof (RippleAssist), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.Inherits));
911

@@ -15,6 +17,43 @@ public static void SetClipToBounds(DependencyObject element, bool value)
1517
public static bool GetClipToBounds(DependencyObject element)
1618
{
1719
return (bool) element.GetValue(ClipToBoundsProperty);
18-
}
20+
}
21+
22+
#endregion
23+
24+
#region StayOnCenter
25+
26+
public static readonly DependencyProperty IsCenteredProperty = DependencyProperty.RegisterAttached(
27+
"IsCentered", typeof(bool), typeof(RippleAssist), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
28+
29+
public static void SetIsCentered(DependencyObject element, bool value)
30+
{
31+
element.SetValue(IsCenteredProperty, value);
32+
}
33+
34+
public static bool GetIsCentered(DependencyObject element)
35+
{
36+
return (bool)element.GetValue(IsCenteredProperty);
37+
}
38+
39+
#endregion
40+
41+
#region RippleSizeMultiplier
42+
43+
public static readonly DependencyProperty RippleSizeMultiplierProperty = DependencyProperty.RegisterAttached(
44+
"RippleSizeMultiplier", typeof(double), typeof(RippleAssist), new FrameworkPropertyMetadata(1.0, FrameworkPropertyMetadataOptions.Inherits));
45+
46+
public static void SetRippleSizeMultiplier(DependencyObject element, double value)
47+
{
48+
element.SetValue(RippleSizeMultiplierProperty, value);
49+
}
50+
51+
public static double GetRippleSizeMultiplier(DependencyObject element)
52+
{
53+
return (double)element.GetValue(RippleSizeMultiplierProperty);
54+
}
55+
56+
#endregion
57+
1958
}
2059
}

0 commit comments

Comments
 (0)