Note that there are some explanatory texts on larger screens.

plurals
  1. POSelecteditem event in an itemtemplate inside a listbox
    text
    copied!<p>I need to have selection changed event inside a listbox itemtemplate. My listbox consists of three textblocks and an image. I want to get the third text block text only and when I select the third textblock the text in the text block will appear as a popup.</p> <p>I used the visual tree to search for a textblock but it take the value of first text block instead of third textblock. What can i do to get the value of 2nd and 3rd textblocks. And I need to trigger a popup only when I click the textblock in the listbox not the whole listbox item.</p> <pre><code>&lt;ListBox Name="listBox1" Width="Auto" SelectionChanged="Listbox1_SelectionChanged"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;Image Height="165" HorizontalAlignment="Left" Margin="10,40,-400,0" VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/&gt; &lt;TextBlock Name="pagetext" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-135,-200,0" Text="{Binding page}" Foreground="#FF170101" /&gt; &lt;TextBlock Name="titletext" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" /&gt; &lt;TextBlock Name="text" Width="1000" TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="195,-167,-200,0" Text="{Binding title}" Foreground="#FF170101" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload