Skip to content

Commit de5ffc4

Browse files
committed
Abstraction and doc fix
1 parent 9d5e2d5 commit de5ffc4

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

components/Shimmer/samples/Shimmer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ issue-id: 390
1212
---
1313
# Shimmer
1414

15-
The Shimmer control can be used to communicate to the user a certain UI element is fetching data or is loading. The `Duration` can be set to change the time in between fades.
15+
The Shimmer control can be used to communicate to the user a certain UI element is fetching data or is loading. `Duration` can be set to set the length of the animation.
1616

1717
> [!SAMPLE ShimmerSample]

components/Shimmer/src/Shimmer/Shimmer.Properties.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,20 @@ public partial class Shimmer : Control
1010
/// Identifies the <see cref="Duration"/> dependency property.
1111
/// </summary>
1212
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
13-
nameof(Duration), typeof(TimeSpan), typeof(Shimmer), new PropertyMetadata(TimeSpan.FromMilliseconds(1600), (s, e) =>
14-
{
15-
var self = (Shimmer)s;
16-
if (self.IsActive)
17-
{
18-
self.TryStartAnimation();
19-
}
20-
}));
13+
nameof(Duration),
14+
typeof(object),
15+
typeof(Shimmer),
16+
new PropertyMetadata(defaultValue: TimeSpan.FromMilliseconds(1600), PropertyChanged));
2117

2218
/// <summary>
2319
/// Identifies the <see cref="IsActive"/> dependency property.
2420
/// </summary>
2521
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(
26-
nameof(IsActive), typeof(bool), typeof(Shimmer), new PropertyMetadata(true, (s, e) =>
27-
{
28-
var self = (Shimmer)s;
29-
var isActive = (bool)e.NewValue;
22+
nameof(IsActive),
23+
typeof(bool),
24+
typeof(Shimmer),
25+
new PropertyMetadata(defaultValue: true, PropertyChanged));
3026

31-
if (isActive)
32-
{
33-
self.StopAnimation();
34-
self.TryStartAnimation();
35-
}
36-
else
37-
{
38-
self.StopAnimation();
39-
}
40-
}));
4127

4228
/// <summary>
4329
/// Gets or sets the animation duration
@@ -56,4 +42,18 @@ public bool IsActive
5642
get => (bool)GetValue(IsActiveProperty);
5743
set => SetValue(IsActiveProperty, value);
5844
}
45+
46+
private static void PropertyChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
47+
{
48+
var self = (Shimmer)s;
49+
if (self.IsActive)
50+
{
51+
self.StopAnimation();
52+
self.TryStartAnimation();
53+
}
54+
else
55+
{
56+
self.StopAnimation();
57+
}
58+
}
5959
}

components/Shimmer/src/Shimmer/Shimmer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
8484
{
8585
ElementCompositionPreview.SetElementChildVisual(_shape, null);
8686

87-
8887
_rectangleGeometry!.Dispose();
8988
_shapeVisual!.Dispose();
9089
_shimmerMaskGradient!.Dispose();

0 commit comments

Comments
 (0)