0

https://github.com/XamlAnimatedGif/WpfAnimatedGif/のライブラリを使用して、wpf を使用してアニメーション gif を解決しようとしています。イメージをイメージにバインドするコードを書きましたが、機能していません。

WPF:

<Image gif:ImageBehavior.RepeatBehavior="Forever"
           gif:ImageBehavior.AnimatedSource="{Binding ElementName=WpfAnimation, Path=ImageStatus}"/>

コードビハインド:

// 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));

    }

エラー:

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.

ありがとうございました。

4

1 に答える 1

1

あなたのバインディングに何か問題があると思います: AnimatedSource は「WpfAnimation」という名前の要素にバインドされています。AnimatedSource を DataContext のプロパティにバインドする必要があります。WpfAnimation が LayoutRoot に似ている場合は、次のような式を使用します。

<Image gif:ImageBehavior.RepeatBehavior="Forever"
           gif:ImageBehavior.AnimatedSource="{Binding ElementName=WpfAnimation, Path=DataContext.ImageStatus}"/>

また、バインド エラーのデバッグ/出力、アニメーション gif がリソースであること、Uri が有効であること、および DataContext がビューに関連付けられていることを確認します。

編集:

ビュー コンストラクターに例外があるようです。

于 2012-10-06T07:40:58.083 に答える