title: Silverlight ItemsControl behavior: how do i get an item i click on?
body: <p>I'm creating a behavior for an ItemsControl with the purpose of selecting the item i click on (and adding it to a list of selected items).</p>
  
  <p>So it's easy to get all the items:</p>
  
  <pre><code>hours = AssociatedObject.ItemsSource as List&lt;Hour&gt;;
  </code></pre>
  
  <p>and of course i could write hours[0].Selected = true;</p>
  
  <p>but then I've got a mouse event, that i tried writing something like this:</p>
  
  <pre><code>void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
      {
          hour = sender as Hour;
      }
  </code></pre>
  
  <p>the problem is, it's not working like i expected... the sender is not an Hour, it's an ItemsControl.</p>
  
  <p>and I've got no indication as to which hour was clicked.
  so what should i do to get the hour?</p>
  
  <p><strong>Edit</strong>
  My code works like this:
  there's an ItemsControl bound to a list of Days.
  each day has a list of hours.
  and to represent that, there is an inner ItemControl bound to (day.)Hours.
  and to represent each hour, there's a border.</p>
  
  <p>looks like this:</p>
  
  <pre><code> &lt;ItemsControl x:Name="daysPanel" Grid.Column="1" ItemsSource="{Binding Days}"&gt;
         &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;ItemsControl x:Name="dayHours" ItemsSource="{Binding Hours}" Grid.Row="1"&gt;
                       &lt;ItemsControl.ItemTemplate&gt;
                              &lt;DataTemplate&gt;
                                    &lt;Border Name="dayHourBorder" Tag="{Binding}" Height="30" BorderBrush="#B0B6BE" Width="193" BorderThickness="1,0,1,1" Background="{Binding Path=Selected, Converter={StaticResource boolToColorConverter}}" &gt;
  </code></pre>