Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save the IsExpanded state in group headers of a listview
    text
    copied!<p>I have quite a tricky problem:</p> <p>I am using a ListView control with the ItemsSource set to a CollectionViewSource including a PropertyGroupDescription to group the ListView elements. The CollectionViewSource looks like this:</p> <pre><code>&lt;CollectionViewSource x:Key="ListViewObjects"&gt; &lt;CollectionViewSource.Source&gt; &lt;Binding Path="CurrentListViewData"/&gt; &lt;/CollectionViewSource.Source&gt; &lt;CollectionViewSource.GroupDescriptions&gt; &lt;PropertyGroupDescription PropertyName="ObjectType" /&gt; &lt;/CollectionViewSource.GroupDescriptions&gt; &lt;/CollectionViewSource&gt; </code></pre> <p>In the ListView I use customize the group headers like this:</p> <pre><code>&lt;ListView.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.ContainerStyle&gt; &lt;Style TargetType="{x:Type GroupItem}"&gt; &lt;Setter Property="Margin" Value="5"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt; &lt;Expander IsExpanded="True"&gt; &lt;Expander.Header&gt; &lt;DockPanel&gt; &lt;TextBlock Text="{Binding Path=Items[0].ObjectType /&gt; &lt;/DockPanel&gt; &lt;/Expander.Header&gt; &lt;Expander.Content&gt; &lt;ItemsPresenter /&gt; &lt;/Expander.Content&gt; &lt;/Expander&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/GroupStyle.ContainerStyle&gt; &lt;/GroupStyle&gt; &lt;/ListView.GroupStyle&gt; </code></pre> <p>As you can see the IsExpanded property of the Expander is set to true. This means that whenever the ListView is refreshed, all Expander controls are expanded.</p> <p>I do however want to save the last state of every Expander. I haven't been able to figure out a way to save a list of Expander states per ObjectType. I was experimenting with a bound HashTable and a Converter, but I failed at providing the ObjectType as a ConverterParameter, because it was always passed as a string. But that may not be the solution anyways.</p> <p>Can somebody give me a hint or an idea for a solution, please? :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload