views:

19

answers:

1

I have a WPF usercontrol that will dynamically have any number of gridviews. Each is essentially the exact same except for the ItemsSource. Therefore each have the same columns and the same RowDetailsTemplate. To be specific what I am actually doing is settings the columns to the bound values and then setting the RowDetailsTemplate to the data template.

What is the best approach to essentially define the GridView once and copy it to all the others. I have tried XamlWriter.Save with the GridView in the resources, but the columns and RowDetailsTemplate are not saved. I have also tried a style, but the columns property is not settable.

Maybe I did something wrong with the two approaches.

+2  A: 

Use an ItemsControl with ItemTemplate. The DataTemplate used for the Itemtemplate should contain the GridView XAML with all the column definitions. Next bind the ItemsControl' ItemSource to a collection of whatever data object you want the GridViews to use as ItemSource.

Wallstreet Programmer