I am trying to use library from https://github.com/XamlAnimatedGif/WpfAnimatedGif/ to solve my animation gif using wpf. I wrote some code to bind the image to the Image, but it is not working.
WPF:
<Image gif:ImageBehavior.RepeatBehavior="Forever"
gif:ImageBehavior.AnimatedSource="{Binding ElementName=WpfAnimation, Path=ImageStatus}"/>
Code Behind:
// Image status property
public readonly DependencyProperty ImageStatusProperty;
public ImageSource ImageStatus
{
get { return (ImageSource)GetValue(ImageStatusProperty); }
set { SetValue(ImageStatusProperty, value); }
}
public MainWindow()
{
InitializeComponent();
ImageStatus = new BitmapImage(new Uri("Images/anipier_e0.gif", UriKind.Relative));
}
Error:
System.Windows.Markup.XamlParseException was unhandled
HResult=-2146233087
Message='The invocation of the constructor on type 'WpfAnimation.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.
Source=PresentationFramework
InnerException: System.ArgumentNullException
HResult=-2147467261
Message=Value cannot be null.
Thank you.
I think something is wrong with your binding : AnimatedSource is binding to an element named “WpfAnimation”. You should bind the AnimatedSource to a property of your DataContext. If WpfAnimation is similar to LayoutRoot, use an expression like this :
Also, check the Debug/Output for binding errors, that the animated gif is a resource, that your Uri is valid, and that a DataContext is associated to your view.
EDIT:
Looks like there is a exception in the view constructor.