title: C# WPF Set animated gif as background
body: <p>I’m stuck on a problem with XAML in a WPF project where I want to have an animated gif as the background of the whole program window.</p>
  <p>I have gone with an external library called WpfAnimatedGif which, to my understanding, must be within an Image-element to work. The problem I'm facing is that I can't set the Image-element as the background of the window.</p>
  <p>I get it to set as background with the ImageBrush-element like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Grid.Background&gt;
      &lt;ImageBrush ImageSource=&quot;Resources/animated.gif&quot;/&gt;
  &lt;/Grid.Background&gt;
  </code></pre>
  <p>The problem with this solution is that the gif doesn't animate, so it's just a static image. For the gif to animate I get it to work with the external library like this:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Border&gt;
      &lt;Image gif:ImageBehavior.AnimatedSource=&quot;Resources\animated.gif&quot;
             gif:ImageBehavior.AutoStart=&quot;True&quot;
             gif:ImageBehavior.RepeatBehavior=&quot;1&quot;/&gt;
  &lt;/Border&gt;
  </code></pre>
  <p>With my limited knowledge of XAML, I don't know how to set that animated gif to fit nicely in the background of the program window like the first example did.</p>
  <p>Is there any easy solution to this?</p>