3

Is there a way that I can click on a WrapPanel's children and get the children, but without having to insert a Click event in every children? Can I just insert a Click event on the WrapPanel?

my code below:

    <ScrollViewer Name="scrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Height="500" Margin="1085,154,-89,0" HorizontalAlignment="Left" Width="267" VerticalAlignment="Top">
        <WrapPanel Name="Agenda" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="265" Background="#FFEEF4FF">
            <Border Name="b06x00" BorderThickness="1" Width="265" BorderBrush="Black" Visibility ="Visible">
                <TextBlock TextWrapping="Wrap" Text="06:00" Width="265" Height="15" Background="White"/>
            </Border>
            ...
            this Border + TextBlock is repeated 70 times. It's an agenda by the way.
            ...
        </WrapPanel>
    </ScrollViewer>
Albert
  • 127
  • 2
  • 13

1 Answers1

4

You can handle for example MouseDown event on your WrapPanel as it will bubble up from any control within that panel

<WrapPanel Name="Agenda" ... MouseDown="Agenda_MouseDown">

and in the event handler you can check for OriginalSource like so:

private void Agenda_MouseDown(object sender, MouseButtonEventArgs e)
{
   var textBlock = e.OriginalSource as TextBlock;
}
dkozl
  • 32,814
  • 8
  • 87
  • 89