How to: Bind Data to RadControls for Silverlight
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
This topic demonstrates how to bind Telerik RadControls for Silverlight such as a RadComboBox or RadGridView to a collection of objects.
Binding Data to RadControls for Silverlight
Suppose, you have a new Silverlight application and you have created a WCF RIA Service based on the Telerik Data Access Domain Model (in this demo, a domain model based on the SofiaCarRental database will be used).
The following example demonstrates how to bind all Categories to a RadGridView control.
<UserControl xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
x:Class="SilverlightApplication.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot"
Background="White">
<telerik:RadGridView x:Name="radGridViewCategories"
Margin="11" />
</Grid>
</UserControl>
using System.ServiceModel.DomainServices.Client;
using System.Windows.Controls;
using SilverlightApplication.Web;
namespace SilverlightApplication
{
public partial class MainPage : UserControl
{
private DemoDomainContext domainContext = new DemoDomainContext();
public MainPage()
{
InitializeComponent();
LoadOperation<Category> loadOperation =
domainContext.Load<Category>(domainContext.GetCategoriesQuery());
radGridViewCategories.ItemsSource = loadOperation.Entities;
}
}
}
Imports System.ServiceModel.DomainServices.Client
Imports SilverlightApplication.Web
Imports SilverlightApplication.Web.SilverlightApplication.Web
Partial Public Class MainPage
Inherits UserControl
Private domainContext As New DemoDomainContext()
Public Sub New()
InitializeComponent()
Dim _loadOperation As LoadOperation(Of Category) =
domainContext.Load(Of Category)(domainContext.GetCategoriesQuery())
radGridViewCategories.ItemsSource = _loadOperation.Entities
End Sub
End Class
A sample output is shown on the snapshot below:
Next Steps
For further reference, check out the following sections: