Skip to content

Commit 8c71f09

Browse files
committed
Update
1 parent 55af261 commit 8c71f09

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

components/Shimmer/src/Dependencies.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@
1313
<ItemGroup Condition="'$(IsUwp)' == 'true'">
1414
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.1.3"/> -->
1515
<PackageReference Include="CommunityToolkit.Uwp.Animations" Version="8.2.241223-build.1367" />
16+
<PackageReference Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
1617
</ItemGroup>
1718

1819
<!-- WinUI 2 / Uno -->
1920
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
2021
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" Version="7.1.11"/> -->
2122
<PackageReference Include="CommunityToolkit.Uwp.Animations" Version="8.2.241223-build.1367" />
23+
<PackageReference Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
2224
</ItemGroup>
2325

2426
<!-- WinUI 3 / WinAppSdk -->
2527
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
2628
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2"/> -->
2729
<PackageReference Include="CommunityToolkit.WinUI.Animations" Version="8.2.241223-build.1367" />
30+
<PackageReference Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
2831
</ItemGroup>
2932

3033
<!-- WinUI 3 / Uno -->
3134
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
3235
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI" Version="7.1.100"/> -->
3336
<PackageReference Include="CommunityToolkit.WinUI.Animations" Version="8.2.241223-build.1367" />
37+
<PackageReference Include="CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator" Version="0.1.250206-build.2040" />
3438
</ItemGroup>
3539
</Project>

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

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,40 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using CommunityToolkit.WinUI;
6+
57
namespace CommunityToolkit.Labs.WinUI;
68

79
public partial class Shimmer : Control
810
{
9-
/// <summary>
10-
/// Identifies the <see cref="Duration"/> dependency property.
11-
/// </summary>
12-
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
13-
nameof(Duration),
14-
typeof(object),
15-
typeof(Shimmer),
16-
new PropertyMetadata(defaultValue: TimeSpan.FromMilliseconds(1600), PropertyChanged));
11+
static TimeSpan _defaultValueForDuration = TimeSpan.FromMilliseconds(1600);
1712

1813
/// <summary>
19-
/// Identifies the <see cref="IsActive"/> dependency property.
14+
/// Gets or sets the animation duration
2015
/// </summary>
21-
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(
22-
nameof(IsActive),
23-
typeof(bool),
24-
typeof(Shimmer),
25-
new PropertyMetadata(defaultValue: true, PropertyChanged));
26-
16+
[GeneratedDependencyProperty(DefaultValueCallback = nameof(DefaultValueForDurationCallback))]
17+
public partial TimeSpan Duration { get; set; }
2718

2819
/// <summary>
29-
/// Gets or sets the animation duration
20+
/// Gets or sets if the animation is playing
3021
/// </summary>
31-
public TimeSpan Duration
22+
[GeneratedDependencyProperty(DefaultValue = true)]
23+
public partial bool IsActive { get; set; }
24+
25+
private static TimeSpan DefaultValueForDurationCallback()
3226
{
33-
get => (TimeSpan)GetValue(DurationProperty);
34-
set => SetValue(DurationProperty, value);
27+
return _defaultValueForDuration;
3528
}
3629

37-
/// <summary>
38-
/// Gets or sets if the animation is playing
39-
/// </summary>
40-
public bool IsActive
30+
partial void OnDurationChanged(TimeSpan newValue)
4131
{
42-
get => (bool)GetValue(IsActiveProperty);
43-
set => SetValue(IsActiveProperty, value);
32+
if (IsActive) TryStartAnimation();
33+
StopAnimation();
4434
}
4535

46-
private static void PropertyChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
36+
partial void OnIsActiveChanged(bool newValue)
4737
{
48-
var self = (Shimmer)s;
49-
if (self.IsActive)
50-
{
51-
self.StopAnimation();
52-
self.TryStartAnimation();
53-
}
54-
else
55-
{
56-
self.StopAnimation();
57-
}
38+
if (IsActive) TryStartAnimation();
39+
StopAnimation();
5840
}
5941
}

components/Shimmer/src/Shimmer/Shimmer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ public partial class Shimmer : Control
4545
private bool _initialized;
4646
private bool _animationStarted;
4747

48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="Shimmer"/> class.
50+
/// </summary>
4851
public Shimmer()
4952
{
5053
DefaultStyleKey = typeof(Shimmer);
5154
Loaded += OnLoaded;
5255
Unloaded += OnUnloaded;
5356
}
5457

58+
/// <inheritdoc/>
5559
protected override void OnApplyTemplate()
5660
{
5761
base.OnApplyTemplate();

components/Shimmer/src/Shimmer/Shimmer.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
</ResourceDictionary>
2121
</ResourceDictionary.ThemeDictionaries>
2222

23-
<Style TargetType="labs:Shimmer">
23+
<Style BasedOn="{StaticResource DefaultShimmerStyle}"
24+
TargetType="labs:Shimmer" />
25+
26+
<Style x:Key="DefaultShimmerStyle"
27+
TargetType="labs:Shimmer">
2428
<Setter Property="Background" Value="{ThemeResource ShimmerBackground}" />
2529
<Setter Property="CornerRadius" Value="4" />
2630
<Setter Property="MinWidth" Value="40" />

0 commit comments

Comments
 (0)