here is a sample for you, in this sample I am controlling the visibility of a subgroup using the IsSelected property of the ListBoxItem
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness=".5" Padding="1">
<StackPanel>
<TextBlock Text="{Binding}" />
<GroupBox Header="child group" MaxHeight="100"
Visibility="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Converter={StaticResource BooleanToVisibilityConverter}}">
Child data
</GroupBox>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Items>
<sys:DateTime />
<sys:DateTime />
<sys:DateTime />
</ListBox.Items>
</ListBox>
hiding child panel with mouse click
- added a toggle button as header
- replaced the original template from button to get desired look
- binded IsChecked property to IsSelected of ListBoxItem
- revised the binding of child panel visibility to a shorter syntax
that's it to have a toggle button to hide the child content
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black" BorderThickness=".5" Padding="1">
<StackPanel>
<ToggleButton x:Name="toggleChild" Content="header text, click to close"
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}">
<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<ContentPresenter />
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<GroupBox Header="child group" MaxHeight="100"
Visibility="{Binding IsChecked, ElementName=toggleChild, Converter={StaticResource BooleanToVisibilityConverter}}">
Child data
</GroupBox>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Items>
<ListItem />
<ListItem />
<ListItem />
</ListBox.Items>
</ListBox>