Skip to content

Commit

Permalink
feat: AnimatedIconSource
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jun 23, 2021
1 parent 79fbf60 commit ceb9887
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.UI.Xaml.Controls
{
public class AnimatedIconSource : IconSource
{
public IconSource FallbackIconSource
{
get => (IconSource)GetValue(FallbackIconSourceProperty);
set => SetValue(FallbackIconSourceProperty, value);
}

public static DependencyProperty FallbackIconSourceProperty { get; } =
DependencyProperty.Register(nameof(FallbackIconSource), typeof(IconSource), typeof(AnimatedIconSource), new PropertyMetadata(null, OnFallbackIconSourcePropertyChanged));

public bool MirroredWhenRightToLeft
{
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}

public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(nameof(MirroredWhenRightToLeft), typeof(bool), typeof(AnimatedIconSource), new PropertyMetadata(false, OnMirroredWhenRightToLeftPropertyChanged));

public IAnimatedVisualSource2 Source
{
get => (IAnimatedVisualSource2)GetValue(SourceProperty);
set => SetValue(SourceProperty, value);
}

public static DependencyProperty SourceProperty { get; } =
DependencyProperty.Register(nameof(Source), typeof(IAnimatedVisualSource2), typeof(AnimatedIconSource), new PropertyMetadata(null, OnSourcePropertyChanged));

public override IconElement CreateIconElement()
{
AnimatedIcon animatedIcon = new AnimatedIcon();
if (Source is { } source)
{
animatedIcon.Source = source;
}
if (FallbackIconSource is { } fallbackIconSource)
{
animatedIcon.FallbackIconSource = fallbackIconSource;
}
if (Foreground is { } newForeground)
{
animatedIcon.Foreground = newForeground;
}
animatedIcon.MirroredWhenRightToLeft = MirroredWhenRightToLeft;

return animatedIcon;
}

protected override DependencyProperty GetIconElementProperty(DependencyProperty sourceProperty)
{
if (sourceProperty == SourceProperty)
{
return AnimatedIcon.SourceProperty;
}
else if (sourceProperty == FallbackIconSourceProperty)
{
return AnimatedIcon.FallbackIconSourceProperty;
}
else if (sourceProperty == MirroredWhenRightToLeftProperty)
{
return AnimatedIcon.MirroredWhenRightToLeftProperty;
}

return base.GetIconElementProperty(sourceProperty);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public Brush Foreground
#nullable enable

public virtual IconElement? CreateIconElement() => default;

protected virtual DependencyProperty? GetIconElementProperty(DependencyProperty sourceProperty) => default;
}
}

0 comments on commit ceb9887

Please sign in to comment.