I have a listbox with a bit of templating. Groups are represented by expanders. The listbox is linked to the filesystem and each folder gets its own expander. Any time a file is renamed, deleted, etc, the listbox's view is refreshed. This works great but once the refresh is called, each of the expanders collapses. I can't seem to find a good way to keep them open. I saw another question that used binding to solve this for a single expander. The issue with a data binding on the "IsExpanded" is that there are an unknown number of expanders and I have no way of knowing how many there will be, what they will be called, etc at design time. Any ideas?
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander VerticalAlignment="Top"
OverridesDefaultStyle="True"
Template="{StaticResource SimpleExpanderTemp}">
<Expander.Header>
<TextBlock VerticalAlignment="Center"
Background="Transparent"
Text="{Binding Path=Name}"
FontFamily="SegoeUI"
FontSize="16"
Foreground="Black"/>
</Expander.Header>
<Expander.Tag>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#696969" />
<GradientStop Offset="1.0" Color="#474747" />
</LinearGradientBrush>
</Expander.Tag>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>