Reputation: 1131
I am working on metro app c#/xaml, I want to bind listview with webservice function which returns List<delNewsletter>
where delNewsletter is class
public class delNewsletter
{
public int Id { set; get; }
public string name { set; get; }
}
and I am binding like this :
lstNews.ItemsSource= await client.GetDeletedNewslettersAsync("token", 1, 2);
but listview item showing content like this
test.win8.delNewsletter
this is method path.
how i can bind listview?
Upvotes: 0
Views: 476
Reputation: 81323
You need to provide DisplayMemberPath
to listView otherwise it will simply call ToString()
on your object and will show class name which it is showing right now.
You can specify it either in code behind or in XAML -
lstNews.DisplayMemberPath = "name";
OR
<ListView DisplayMemberPath="{Binding name}"/>
But in case you want to show both Id and name in your listView, you need to provide template to your listView -
<ListView>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Id}"/>
<GridViewColumn DisplayMemberBinding="{Binding name}"/>
</GridView>
</ListView.View>
</ListView>
Upvotes: 1
Reputation: 2218
could you try to override ToString
method of your delNewsletter class.
to something like that:
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "Name: {0}, Id: {1}", Name, Id);
}
Upvotes: 0