This help article shows how to create a DataGrid from scratch using the DataGrid related classes in the Telerik UI for Windows Universal.
First, add a reference to the needed assemblies:
Alternatively, you can add a reference to Telerik UI for Windows Universal SDK.
Next, add the Telerik.UI.Xaml.Controls.Grid namespace:
XAML | Copy |
---|
xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid" |
Now declare the DataGrid which is
in the Telerik.UI.Xaml.Controls.Grid namespace. Here is the XAML declaration:
XAML | Copy |
---|
<telerikGrid:RadDataGrid x:Name="DataGrid"/> |
Next, load it with data. This is, pass Business objects to the DataGrid.ItemsSource property.
By default, the DataGrid control will auto generate rows depending on the number of objects and columns depending on the object's properties.
Here's how we can achieve this:
C# | Copy |
---|
this.DataGrid.ItemsSource = new List<Data>
{
new Data { Country = "India", Capital = "New Delhi"},
new Data { Country = "South Africa", Capital = "Cape Town"},
new Data { Country = "Nigeria", Capital = "Abuja" },
new Data { Country = "Singapore", Capital = "Singapore" }
}; |
Where Data is a custom business object:
C# | Copy |
---|
public class Data
{
public string Country
{
get;
set;
}
public string Capital
{
get;
set;
}
} |
And the result is: