How to bind data in WrapDataGrid control

May 14, 2009 at 2:56 AM


I am new to MSCUI controls,

I have gone through the sample code of MedicationsListView control,

I want to display data in WrapDataGrid control, I am not able to understand from the sample that ,how should I use the DataContext property of WrapDataGrid to bind the data

can anyone tell me, how do I bind the data to WrapDataGrid?

Thanks in Advance




May 14, 2009 at 9:35 AM

The DataContext of the WrapDataGrid should be set to a collection, or other IEnumerable object.

Imagine you have a class, Car : FrameworkElement, with two properties of type string, Model and Manufacturer. I deally these properties should be a dependencyproperty

You could create a collection class called CarCollection : Collection<Car>

You set this as the DataContext of the WrapDataGrid.

 In the XAML for you page, where you have the WrapDataGrid declared, you specify how many columns you require by creating WrapDataGridColumn objects. What you want to see in each column is controlled by the CellTemplate. this is what will be shown in each cell in that column.

If you want a column to show the Model, you would use something like below. Every object in the car collection will then be set to the datacontext of the Cells in a Row in the grid.

                                <TextBlock Margin="0,0,10,0" HorizontalAlignment="Right"
                                Text="{Binding Model}"/>


Hope that helps.