Note that there are some explanatory texts on larger screens.

plurals
  1. PORead the Value of an Item in a listbox
    text
    copied!<p>I'm developing a small windows store application in C# where I have populated the <strong>values</strong> and <strong>content</strong> for a <em>listbox</em> using the following code snippet.</p> <p>code 1 : adds the song title as a <em>item</em> to a <em>listbox</em>, using the Song <em>class</em> to create the <em>item</em></p> <pre><code> private void addTitles(string title, int value) { Song songItem = new Song(); songItem.Text = title; songItem.Value = value; listbox1.Items.Add(songItem); // adds the 'songItem' as an Item to listbox } </code></pre> <p>code 2 : Song <em>class</em> which is used to set values to each <em>item</em> ('songItem')</p> <pre><code>public class Song { public string Text { get; set; } public int Value { get; set; } public override string ToString() { return Text; } } </code></pre> <p>Population content to the <em>listbox</em> is functioning currently.</p> <p>What I want is to get the 'Value' of each <em>item</em> on a Click event, on run-time. </p> <p>For that purpose, how can I read(extract) the <strong>Value</strong> of the selected Item in the <em>listbox</em>, in C#? ( Value is the songItem.Value )</p> <p>code 3 : I have tried this code, as trying to figure out a solution, but it didn't work</p> <pre><code> private void listbox1_tapped(object sender, TappedRoutedEventArgs e) { Int selectedItemValue = listbox1.SelectedItem.Value(); } </code></pre> <p>Therefore it would be really grateful if someone can help me, as I'm an Amateur. </p>
 

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