Search code examples
c#wpflistviewanonymous-types

Get values from anonymous object


I have a ListView (in WPF app) which I fill it programmatically:

l1.Items.Add(new
{
    AA = aa++,
    Description = descriptions[k],
    Shop = names[k + 2],
    Price = price
});

I want to take the first row and the value of column price. I can take the object

object b = l1.Items.GetItemAt(0);

but I can't take the price.


Solution

  • You can use the dynamic keyword for that.

    dynamic b = l1.Items.GetItemAt(0); 
    var price = b.Price;