Reputation: 932
I have got a listbox and I have to populate that with the elements from the query. The query is,
var query = from b in context.table select b;
List<Tab> reclist = q.ToList();
using LINQ how can I print all the obtained values in the listbox?
Upvotes: 1
Views: 431
Reputation: 2735
You'll need to create a DataTemplate
containing a TextBlock
whose Text
property you bind to a property on your object. So, some XAML something like;
<ListBox x:Name="MyListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Presuming your Tab
class has a property called Name
. Obviously if it doesn't you'll want to change the {Binding Name}
portion of the XAML to match the property name that you want to display in the ListBox
.
You then bind to your item;
MyListBox.ItemsSource = reclist;
Upvotes: 3