Using WPF, assuming I have 2 classes:
public class SimpleType {
public string Name { get; set; }
}
public class ComplexType {
public SimpleType Item1 { get; set; }
public SimpleType Item2 { get; set; }
}
and I want to bind a collection of these objects to a gridview, and in other places as well. I always want SimpleType to be shown a particular way, so I made a datatemplate for it in the XAML (there are more properties but I'm trying to simplify the example as much as possible):
<DataTemplate x:Key="SimpleTypeTemplate" DataType="{x:Type local:SimpleType}">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=Name}" />
</StackPanel>
</DataTemplate>
How do I bind this to a gridview?
<GridView>
<GridViewColumn CellTemplate="{StaticResource ResourceKey=SimpleTypeTemplate}" />
<GridViewColumn CellTemplate="{StaticResource ResourceKey=SimpleTypeTemplate}" />
</GridView>
How do I indicate that I want to use the Item1 property for the first cell and Item2 for the second? Using DisplayMemberBinding let me specify the property, but I couldn't reuse the template. If I specify the CellTemplate, I can't seem to figure out how to specify the property. Am I missing something obvious, or am I just going about this the wrong way entirely? Thanks for any help.
edit: Not sure if it matters, but I think I should specify the gridview is within a listview where I specify the ItemsSource property for binding to an IObservableCollection in the underlying class.