Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dp Sourcestream #70

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/LottieSharp/LottieSharp.WPF/LottieAnimationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public AnimationInfo Info

public event EventHandler OnStop;

public Stream SourceStream
{
get => (Stream)GetValue(SourceStreamProperty);
set => SetValue(SourceStreamProperty, value);
}

public string FileName
{
get => (string)GetValue(FileNameProperty);
Expand Down Expand Up @@ -119,12 +125,23 @@ public RepeatMode Repeat
public static readonly DependencyProperty RepeatProperty =
DependencyProperty.Register("Repeat", typeof(RepeatMode), typeof(LottieAnimationView), new PropertyMetadata(RepeatMode.Restart));

public static readonly DependencyProperty SourceStreamProperty =
DependencyProperty.Register("SourceStream", typeof(Stream), typeof(LottieAnimationView), new PropertyMetadata(null, SourceStreamPropertyChangedCallback));

public static readonly DependencyProperty FileNameProperty =
DependencyProperty.Register("FileName", typeof(string), typeof(LottieAnimationView), new PropertyMetadata(null, FileNamePropertyChangedCallback));

public static readonly DependencyProperty ResourcePathProperty =
DependencyProperty.Register("ResourcePath", typeof(string), typeof(LottieAnimationView), new PropertyMetadata(null, ResourcePathPropertyChangedCallback));

private static void SourceStreamPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is LottieAnimationView lottieAnimationView && e.NewValue is Stream stream)
{
lottieAnimationView.SetAnimationFromStream(stream);
}
}

private static void FileNamePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is LottieAnimationView lottieAnimationView && e.NewValue is string assetName)
Expand All @@ -141,6 +158,19 @@ private static void ResourcePathPropertyChangedCallback(DependencyObject depende
}
}

private void SetAnimationFromStream(Stream stream)
{
try
{
SetAnimation(stream);
}
catch (Exception)
{
Debug.WriteLine($"Unexpected error when loading {stream}");
throw;
}
}

private void SetAnimationFromFile(string assetName)
{
try
Expand Down