How can I get a listbox's selected item binded element?

user2950509

So here is my problem: I am looking to find the binded string named "id" from the selected element in my listbox. Here is my .xaml:

<ListBox Name="lstView">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid/>                                   
                <TextBlock Text="{Binding id}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And my c# which sends data to fill the listbox:

var articles = root.data.movies.Select(m => new Article { Name = m.title, ImagePath = m.medium_cover_image, Year = m.year.ToString() }).ToList();
foreach (Article s in articles)
{
    this.lstView.Items.Add(new Article {id = m.id.ToString()});                                   
}

I have tried various different scenarios, but nothing has worked yet :/

user2950509

Actually I found a way simpler way to get this working (thanks for your help anyway):

Article selectedArticle = lstView.SelectedItem as Article;

And then to get any string binded to that element you call:

selectedArticle.nameofthebindedstring            

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the string of binded item in a listbox programmatically?

From Dev

How to get selected item of a listbox within a listbox

From Dev

How can I make selected item in listbox scroll to the top?

From Dev

The selected item in a listbox is null how can i fix that?

From Dev

How to get listbox selected item value

From Dev

How can i remove the blue color wraping the selected item in listBox1 when clicking on item?

From Dev

How to get the index of a selected item in listbox and add to listbox two with button?

From Dev

How to get the index of a selected item in listbox and add to listbox two with button?

From Dev

How can I control what's displayed in a Binded, ObserverableCollection ListView

From Dev

How to get an image to display in Picturbox from a Listbox selected item

From Dev

How to get particular property from item selected in ListBox

From Dev

How to set the Selected Item's text color in Html.Listbox

From Dev

Visual Basic: How can I get all selected Values from a Listbox (Selectionmode Multisimple) using a Loop?

From Dev

Which way I can get ListBox item coords?

From Dev

Get selected item from databound ListBox

From Dev

Get object information of selected listbox item

From Dev

get Values of one listbox item selected

From Dev

Get object information of selected listbox item

From Dev

Listbox binding get selected item value

From Dev

How can I verify the selected item in the list?

From Dev

How can I get the selected row's value of a qtablewidget in PyQt?

From Dev

Listbox Not Displaying Data (Is Binded With Item Template)

From Dev

How can i set one spinner's selected item control other spinner's items?

From Dev

how to change the background of the selected item in a listbox?

From Dev

how to change the background of the selected item in a listbox?

From Dev

Tkinter Listbox How to tell if an item is selected

From Dev

How can I remove an item from a listbox without using "Contains"?

From Dev

How can i add item in listbox each time that an button was clicked?

From Dev

How can I remove more than one item from a listbox?

Related Related

  1. 1

    How to get the string of binded item in a listbox programmatically?

  2. 2

    How to get selected item of a listbox within a listbox

  3. 3

    How can I make selected item in listbox scroll to the top?

  4. 4

    The selected item in a listbox is null how can i fix that?

  5. 5

    How to get listbox selected item value

  6. 6

    How can i remove the blue color wraping the selected item in listBox1 when clicking on item?

  7. 7

    How to get the index of a selected item in listbox and add to listbox two with button?

  8. 8

    How to get the index of a selected item in listbox and add to listbox two with button?

  9. 9

    How can I control what's displayed in a Binded, ObserverableCollection ListView

  10. 10

    How to get an image to display in Picturbox from a Listbox selected item

  11. 11

    How to get particular property from item selected in ListBox

  12. 12

    How to set the Selected Item's text color in Html.Listbox

  13. 13

    Visual Basic: How can I get all selected Values from a Listbox (Selectionmode Multisimple) using a Loop?

  14. 14

    Which way I can get ListBox item coords?

  15. 15

    Get selected item from databound ListBox

  16. 16

    Get object information of selected listbox item

  17. 17

    get Values of one listbox item selected

  18. 18

    Get object information of selected listbox item

  19. 19

    Listbox binding get selected item value

  20. 20

    How can I verify the selected item in the list?

  21. 21

    How can I get the selected row's value of a qtablewidget in PyQt?

  22. 22

    Listbox Not Displaying Data (Is Binded With Item Template)

  23. 23

    How can i set one spinner's selected item control other spinner's items?

  24. 24

    how to change the background of the selected item in a listbox?

  25. 25

    how to change the background of the selected item in a listbox?

  26. 26

    Tkinter Listbox How to tell if an item is selected

  27. 27

    How can I remove an item from a listbox without using "Contains"?

  28. 28

    How can i add item in listbox each time that an button was clicked?

  29. 29

    How can I remove more than one item from a listbox?

HotTag

Archive