How to: Iterate through groups and toggle their expanded state

This example demonstrates how the NavBarControl.Groups collection can be iterated programmatically, and the expanded state of groups can be toggled by using a group's NavBarGroup.IsExpanded property.

The result is demonstrated by the following image.

Example-ToggleExpandedState.png

Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    For i As Integer = 0 To navBarControl1.Groups.Count - 1
        Dim currentGroup As NavBarGroup = navBarControl1.Groups(i)
        currentGroup.IsExpanded = Not currentGroup.IsExpanded
    Next i

End Sub