How to create reusable Listvew/Datagrid & bind with two diffrent collection propery in two diffrent ViewModel in WPF
Loading
How to create reusable Listvew/Datagrid & bind with two diffrent collection propery in two diffrent ViewModel in WPF
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandhiya PriyaPosted Jan 2, 2026, 10:59 AM
you want a reusable ListView/DataGrid in WPF that can bind to different collection properties across different ViewModels. The key is to decouple the control from the specific ViewModel by using dependency properties or DataTemplates.
Here’s a complete approach:
Solution 1: Use a UserControl with Dependency Property
1. Create a Reusable UserControl
2. Add Dependency Property in Code-Behind
3. Use in Different Views
Here,
StudentsandEmployeesare two different collection properties in two different ViewModels, but the same reusable control works.Solution 2: Use DataTemplates with ContentControl
If you want different column definitions depending on the ViewModel:
The
ContentControlautomatically picks the right template based on the ViewModel type.Note
Dependency Property approach ? Best for a single reusable grid with dynamic binding.
DataTemplate approach ? Best when you need different column definitions per ViewModel.
Both approaches keep your UI reusable and clean.