WPF control with many GridViews
I have a WPF user control that will dynamically have any number of GridView
s. 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 开发者_Go百科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.
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
's ItemSource
to a collection of whatever data object you want the GridView
s to use as ItemSource
.
精彩评论