I have a WPF ListBox with several headings. I acheived this by having a GroupStyle in which I define how each header will look:
<ListBox DataContext="{StaticResource MyGroups}" ItemsSource="{Binding}">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<!-- my header stuff -->
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
<!-- ListBox.ItemTemplate.. not shown -->
</ListBox>
Somehow, this causes the individual ListBoxItems to be slightly “indented” under their respective headers (Removing the GroupStyle removes the indentation, along with all the headers though).
I sort of see why they would want them indented by default, but is there anyway to remove that small left padding? I have tried to define a style for ListBoxItem to set the Padding = 0, but the outcome is the same.
The only way I could remove the indentation was to introduce my own control template for GroupItem in GroupStyle.ContainerStyle.
The template consists of two grid rows, one for the header, and one for the group items.