Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming the following XAML:</p> <pre><code>&lt;ListBox Name="Index_list" SelectionChanged="on_selection"&gt; &lt;!-- These items could also be added in code --&gt; &lt;TextBlock Text="list box option 1" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 2" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 3" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 4" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 5" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 6" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 7" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 8" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 9" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 10" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;TextBlock Text="list box option 11" Style="{StaticResource PhoneTextExtraLargeStyle}" /&gt; &lt;/ListBox&gt; </code></pre> <p>you can get at the text from the selected TextBlock in the following ways.<br> <em>(Note that use of a MessageBox is purely for demonstration.)</em></p> <pre><code>private void on_selection(object sender, SelectionChangedEventArgs e) { // As the listbox is named we can do this: if (Index_list.SelectedIndex &gt;= 0) { MessageBox.Show((Index_list.SelectedItem as TextBlock).Text); } // if the listbox wasn't named we could do this: if (sender is ListBox) // always good to double check { var sal = sender as ListBox; if (sal.SelectedIndex &gt;= 0) { MessageBox.Show((sal.SelectedItem as TextBlock).Text); } } // Or we could use the EventArgs: if (e.AddedItems.Count == 1) { MessageBox.Show((e.AddedItems[0] as TextBlock).Text); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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