Wriju's BLOG

.NET, Cloud and everything

ADO.NET Entity Framework 4.0 : DataBinding with Windows Presentation Foundation (WPF)

This post is to give an idea on how easily we can bind and create master details display in WPF.


Here I am using Northwind sample database and using Category and Products tables. These two tables are connected with each other through CategoryId. We will create a model using these two tables. Please ensure that you check the Foreign Key checkbox while selecting table in the EF4 model creation wizard.


Now, add two controls ListBox with id listBox1 and DataGrid with dataGrid1. Set the AutoGeneratedColumns to checked for the DataGrid.


Now open the Show Data Source from Visual Studio from Data Source menu.


Drop Category to listBox1 and Product (under Category) to dataGrid1. That’s all. Not a single line of code is required.