DataBinding to ListView
Posted
by Neir0
on Stack Overflow
See other posts from Stack Overflow
or by Neir0
Published on 2010-04-04T17:10:50Z
Indexed on
2010/04/04
18:43 UTC
Read the original article
Hit count: 466
Hi, I have a class
public class Foo
{
public List<string> list1 { get; set;}
public List<string> list2 { get; set; }
public string url;
}
and a ListView with two columns
<ListView Name="listview" ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Header="list1"
DisplayMemberBinding="{Binding Path=list1}" />
<GridViewColumn Header="list2"
DisplayMemberBinding="{Binding Path=list2}" />
</GridView>
</ListView.View>
</ListView>
How i can to bind instance of Foo class to ListView?
Here i set DataContext
listview.DataContext = new Foo()
{
list1 = new[] { "dsfasd", "asdfasdf", "asdf", "asdfasd" }.ToList(),
list2 = new[] { "dsfasd", "asdfasdf", "asdf", "asdfasd" }.ToList()
};
But it's not work.
© Stack Overflow or respective owner