How to create reusable Listvew/Datagrid & bind with two diffrent collection propery in two diffrent ViewModel in WPF
Create reusable Listvew/Datagrid can bind2 diff property of VM in WPF
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 2, 2026, 5:59 AM EST
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
public partial class ReusableGrid : UserControl { public ReusableGrid() { InitializeComponent(); } public IEnumerable DataSource { get { return (IEnumerable)GetValue(DataSourceProperty); } set { SetValue(DataSourceProperty, value); } } public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register("DataSource", typeof(IEnumerable), typeof(ReusableGrid), new PropertyMetadata(null)); }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.