Introduction
Master–detail UIs are notorious for slowing WPF applications down. Expanding detail rows often multiplies the visual tree, killing performance and scroll fluidity. This guide shows how to keep things snappy by combining MVVM, async commands, and virtualization inside a WPF DataGrid.
What You’ll Build
- Master grid of Orders
- On expand → details load asynchronously (Items per Order)
- Smooth scrolling with row virtualization and recycling
Key XAML (trimmed for clarity)
<DataGrid ItemsSource="{Binding Orders}"
EnableRowVirtualization="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Items}" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
- Virtualization flags keep scrolling smooth.
- RowDetailsTemplate bound to a lightweight Items view.
- Async command loads details without blocking UI.
MVVM Pattern
- ViewModel exposes ObservableCollection<OrderVm>.
- Each OrderVm loads details with a Task-based async method.
- Placeholder UI shown instantly while data fetch runs.
- Cancellation tokens ensure stale loads are canceled during rapid navigation.
Performance Tips
- Keep detail templates lightweight (avoid heavy converters).
- Defer expensive bindings until IsVisible == true.
- Cache small detail views if reused frequently.
Developer Wins
- Users perceive instant expand response.
- No UI thread stalls during slow I/O.
- Clean MVVM separation → easier testing and maintenance.
👉 Get the full working sample and test it against your own dataset.
Start your 45-day trial here: https://xceed.com/trial/
FAQ
Q: Can I prefetch details for the next rows?
A: Yes. Prefetch adjacent rows on scroll idle, but keep requests cancellable.
Q: Will virtualization break details?
A: No. Details render on demand. Just keep templates lightweight.
Q: How do I theme the details consistently?
A: Apply Toolkit Plus themes or shared resource dictionaries.