c# - Read the Value of an Item in a listbox -


i'm developing small windows store application in c# have populated values , content listbox using following code snippet.

code 1 : adds song title item listbox, using song class create item

    private void addtitles(string title, int value)      {         song songitem = new song();          songitem.text = title;         songitem.value = value;         listbox1.items.add(songitem); // adds 'songitem' item listbox     } 

code 2 : song class used set values each item ('songitem')

public class song {     public string text { get; set; }     public int value { get; set; }     public override string tostring()     {         return text;     } } 

population content listbox functioning currently.

what want 'value' of each item on click event, on run-time.

for purpose, how can read(extract) value of selected item in listbox, in c#? ( value songitem.value )

code 3 : have tried code, trying figure out solution, didn't work

 private void listbox1_tapped(object sender, tappedroutedeventargs e)         {            int selecteditemvalue = listbox1.selecteditem.value();         } 

therefore grateful if can me, i'm amateur.

not sure "tappedroutedeventargs", do

private void listbox1_tapped(object sender, tappedroutedeventargs e)         {            var selectedsong = (song)listbox1.selecteditem;            if (selectedsong != null) {               var val = selectedsong.value;               }         } 

because selecteditem object (which doesn't know value property), have cast song first.

by way, value property, not method, don't need parenthesis.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -