views:

21

answers:

1

I have a DataGrid that is displaying some data at multiple points in my SL 4 app. I would like reduce redundancy. Is the correct way to do this by extracting it into a UserControl?

I did this. However, instead of setting dataGrid.ItemsSource in the code behind, I'm setting myDataGridControl.ItemsSource. However, MyDataGridControl doesn't have that property by default. Is there some way to forward those calls/properties to the DataGrid? Do I want to subclass DataGrid instead of containing it? Or is there another way to keep SL DRY?

A: 

Your user control has the data grid as its only child so if you want to expose ItemsSource , you'll need to add a property to the user control which is mapped to the datagrid's itemsource: i.e. getter returns the datagrid's itemsource and setter sets it

vc 74
Ok, and I must repeat this process for every property I wish to expose?
Rosarch
It gets a bit uglier than that because it is highly likely that this ItemsSource property needs to be a binding target, hence would need to be a DependencyProperty.
AnthonyWJones
yes, that is correct
Muad'Dib
Better off inheriting from DataGrid then I guess...
vc 74