I have the following markup (xaml):
<ListBox Name="lbEurInsuredType" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="30"></ColumnDefinition><ColumnDefinition Width="2"></ColumnDefinition>
<ColumnDefinition Width="30"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}"></TextBlock>
<TextBox Text="{Binding Uw}" Grid.Column="1"></TextBox>
<TextBox Text="{Binding Partner}" Grid.Column="3"></TextBox>
</Grid>
</DataTemplate></ListBox.ItemTemplate>
</ListBox>
This all looks ok, but now above column 1 and 3 I want to place a header. Can anyone show me how I add headers to my two columns.
I haven't run this so there might be some issue with the code but this will give you the idea to add headers to the ListBox
Even Listbox can be inside a user control with dynamic data template
ListBox has no
HeaderTemplate
.ListView
is not the best option because it does not supportWidth="*"
. If you get desperate and go toDataGrid
you might be getting a lot more than you need. The solution is to use aHeaderedItemsControl
Just change the name of the Collection you are binding to and change the binding properties.
Listview is surely the best option, but, if you need to use a listbox you could modify the template of the listbox in this way.
I recommend that you use a
ListView
instead which more appropriate to you case, you could use aGridView
inside and define the columns that you need then restyle them much more easilyYou could nest a label (or a text block for that matter) inside one of the column definitions and style it accordingly.