MVVM or Custom Control

Nov 4, 2010 at 6:12 PM

Hi! I have a Silverlight project where I need a Control that is basically a DataGrid with a “New” button and “Remove” buttons in the rightmost column. Which would you guys recommend:

1. I create a CustomDataGridView.xaml and a CustomDataGridViewModel.cs. I put a ContentControl in my ShellView named MyDataGrid and a public CustomDataGridViewModel MyDataGrid { get; set; } in my ShellViewModel.

2. I create a CustomDataGrid.xaml and put some code in the code behind. I put a <local:CustomDataGrid source=”MyCollection”> in my ShellView and pretend it is a regular control.

I have no idea which solution is the best. I think both have their pros and cons. What do you think?

Nov 4, 2010 at 8:17 PM

I noticed that using the first solution often yields better results in terms of manteinability.
Using an UserControl at Xaml side is appealing, but you can slighlty end up incorportating some application logic (or even worst, business logic) after some time.
On the other hand, starting with a VM+View solution is scalable: you can decompose the VM if its complexity grows, or you can incorporate the View part in the hosting view if it gets simpler (keeping the VM in place).

Nov 5, 2010 at 12:27 PM

Thanx, I'm going with 1. then.