I have a listview in which’s groupstyle, i have defined an expander(code below), i programmatically add many items to the listview which get added to the appropriate expander and if the expander does not exist fo the new item, it gets created dynamically.
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True" >
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
So what needs to be done is that when a new item is added, the focus should divert to that item and the expander should be expanded while collapsing all else…
Use a binding to see if the lists SelectedItem is part of the Group that we are bound to.
You will Bind IsExpanded to the lists SelectedItem, with a converter parameter that is bound to the viewmodel and have the converter simply check to see if the arguments match.
The converter simply returns true or false