Edit this page

In-Memory Data

The purpose of this tutorial is to show you how to create in-memory data and use it in the context of your Silverlight application. The following common tasks will be examined:

  • Creating in-memory data.

  • Setting it as a data source/data context in Silverlight application.

This tutorial will use objects and data from the Northwind database, which can be downloaded from here.

Creating In-Memory Data

Here is a sample code showing how to create in-memory data:

C#

public List<Categories> categories = new List<Categories>();
public void CreateCategories()
{
    Categories c = new Categories();
    c.CategoryID = 1;
    c.CategoryName = "Beverages";
    c.Description = "Soft drinks, coffees, teas, beers, and ales";
    categories.Add( c );
    c = new Categories();
    c.CategoryID = 2;
    c.CategoryName = "Condiments";
    c.Description = "Sweet and savory sauces, relishes, spreads, and seasonings";
    categories.Add( c );
    c = new Categories();
    c.CategoryID = 3;
    c.CategoryName = "Confections";
    c.Description = "Desserts, candies, and sweet breads";
    categories.Add( c );
}

VB.NET

Public categories As New List(Of Categories)()
Public Sub CreateCategories()
    Dim c As New Categories()
    c.CategoryID = 1
    c.CategoryName = "Beverages"
    c.Description = "Soft drinks, coffees, teas, beers, and ales"
    categories.Add(c)
    c = New Categories()
    c.CategoryID = 2
    c.CategoryName = "Condiments"
    c.Description = "Sweet and savory sauces, relishes, spreads, and seasonings"
    categories.Add(c)
    c = New Categories()
    c.CategoryID = 3
    c.CategoryName = "Confections"
    c.Description = "Desserts, candies, and sweet breads"
    categories.Add(c)
End Sub

Setting In-Memory Data as DataSource In Silverlight Application

There are numerous ways to set in-memory data as data source:

  • Using XAML. Here is a sample XAML code:

XAML

<UserControl.Resources>
        <example:categories x:Key="DataSource"/>       
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
        <telerikNavigation:RadTreeView x:Name="radTreeView"
           ItemsSource="{Binding Source={StaticResource DataSource}"/>
</Grid>
  • In code-behind:

C#

radTreeView.ItemsSource = categories;
// Or
radTreeView.DataContext = categories;

VB.NET

radTreeView.ItemsSource = categories
' Or'
radTreeView.DataContext = categories

See Also