WPF loading animation (spinner) that keeps the UI responsive
Codemia Knowledge Hub ·
A WPF loading spinner is easy to draw with a Storyboard. The part that matters more is keeping the UI thread free while the real work runs, because blocking it freezes the animation you just built.
A simple spinner with a Storyboard
A small rotating shape is enough for a clean loading indicator:
The key piece is the continuously animated RotateTransform.
Run the real work asynchronously
If the click handler does heavy work on the UI thread, the animation stops even though the XAML is correct. Use async and await the background work:
The slow work happens off the UI thread, so the UI thread stays free to animate.
Why a frozen spinner is a threading problem
WPF renders and updates UI elements on the UI thread, and a loading animation is no exception. The spinner cannot update smoothly while your code runs any of these on that thread:
- synchronous network calls
- large file reads
- long CPU loops
- blocking sleeps
Show the spinner only while work is running
The indicator should reflect a real state change:
- show it when work begins
- hide it when work completes or fails
- optionally replace it with a success or error message
Users lose trust in a spinner that keeps going after the task has finished or deadlocked. Clearing the flag in a finally block, as above, covers the failure path too.
Binding IsLoading from a view model
In larger WPF applications, keep the loading state in a view model and bind Visibility or IsEnabled to it. The animation stays in XAML while the view model exposes IsLoading. That separates visual behavior from application logic and keeps code-behind small.
A simple spinner with correct async behavior usually beats a flashy control on a blocked UI thread. If the spinner freezes, look for blocking code on the UI thread first.
Related reading
- WPF MVVM How to close a window
- WPF TextBox won't fill in StackPanel
- WPF updating the itemssource in a ListBox with an async method
- WPF User Control Parent
- WPF Window with transparent background containing opaque controls
- Wrap a delegate in an IEqualityComparer
- Wrapping ManualResetEvent as awaitable task
- Wrapping StopWatch timing with a delegate or lambda?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.