I have a data-bound ListView in WPF with the ListView items being rendered as RadioButtons. I want to use a GridView to display these in a grid. I can find numerous examples for using a GridView where the data is to be displayed in columns (with different item properties in each column) but I want an entire child item in each cell not the rendering of a specific property.
In other words, I'd like something like this:
<ListView ItemsSource="{Binding OptionItems}">
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<RadioButton
Content="{Binding Option.Value}"
IsChecked="{Binding IsChecked}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
but with the column repeated, with the desired result that the items spread evenly three (or however many I set) to a row.
Is there a way of doing this? Is a GridView even the correct way of trying?
I currently have the items displayed using an ItemsControl and a WrapPanel but this isn't spacing the columns evenly and, despite much tweaking, isn't achieving the correct effect.
I have thought of achieving this by having a contrived property in my ViewModel that collects the items into groups of three (or however many I set) and then showing each sub-item from within the group in each column but that does seem a very ugly solution.