Data Binding Of ListBox In Silverlight
Sign in

Data Binding of ListBox in Silverlight

Software Engineer
In this post I'll show how to use data binding with the listbox in silverlight. Suppose that you have a class Person which contains ID, Name, Address like this:

public class Person

{

public int ID { get; set; }

public string Name { get; set; }

public string Address { get; set; }

}

Now i have a List lstPerson. And i want to show Name in the ListBox.

So in the .xaml I define a listbox as:
<ListBox x:Name="ListBoxPerson">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ForeignKeyName}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>


And now in .xaml.cs i define the itemSource of the ListBox as ListBoxPerson.ItemSource=lstPerson;
So, this is so simple to use data binding in ListBox.

start_blog_img