Introduction
I have found a solution for GIF animation by only using Windows Forms. Based on this, I have solved this problem in WPF (.NET 3.5).
Using the Code
I have created my own class:
public class AnimatedImageControl : UserControl {...}
and overridden the OnRender
function:
protected override void OnRender(DrawingContext p_drawingContext)
{
ImageAnimator.UpdateFrames(m_animatedImage);
Graphics gr = Graphics.FromHwnd(m_hwnd.Handle);
gr.FillRectangle(m_brush, m_rectangle);
gr.DrawImage(m_animatedImage, m_rectangle);
}
Points of Interest
The main trick is using Graphics
instead of DrawingContext
.
It works properly only if the background is a solid color brush, because calling FillRectangle()
is necessary.