title: Enumerate ItemsControl.Items as UIElements
body: <p>I have a list of hyperlinks that are displayed through an <code>ItemsControl</code>, something like this:   </p>
  
  <pre><code> &lt;ItemsControl x:Name="SubMenu" Visibility="Collapsed"&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;HyperlinkButton Content="{Binding Name}"
                                   NavigateUri="{Binding Url}"
                                   TargetName="ContentFrame"
                                   Style="{StaticResource LinkStyle}"
                                   /&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;StackPanel Style="{StaticResource LinksStackPanelStyle}"
                              VerticalAlignment="Center"
                              HorizontalAlignment="Left" /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
      &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>what I need to do is enumerate the actual hyperlinks in the submenu, something like this:</p>
  
  <pre><code>    foreach (UIElement child in SubMenu.Items) // this does not work!
      {
          HyperlinkButton hb = child as HyperlinkButton;
          if (hb != null &amp;&amp; hb.NavigateUri != null)
          {
              if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
              {
                  VisualStateManager.GoToState(hb, "ActiveLink", true);
              }
              else
              {
                  VisualStateManager.GoToState(hb, "InactiveLink", true);
              }
          }
      }
  </code></pre>
  
  <p>The problem is that I can´t seem to find a way to enumerate the actual UI elements in the ItemsCollection.Items.</p>
  
  <p>Anyone know how to do this or a possible workaround?</p>
  
  <p>I can mention that what I´m trying to do is build a menu and submenu that display the hyperlinks clicked as a sort of breadcrumb.</p>
  
  <p><strong>UPDATE:</strong>
  The best thing would be if I could get to that stackpanel somehow because this code seems to work:</p>
  
  <pre><code>    foreach (UIElement child in LinksStackPanel.Children)
      {
          HyperlinkButton hb = child as HyperlinkButton;
          if (hb != null &amp;&amp; hb.NavigateUri != null)
          {
              if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
              {
                  VisualStateManager.GoToState(hb, "ActiveLink", true);
              }
              else
              {
                  VisualStateManager.GoToState(hb, "InactiveLink", true);
              }
          }
      }
  </code></pre>