Silverlight
  Home arrow Silverlight arrow Silverlight 4.0 CollectionViewSource with ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SILVERLIGHT

Silverlight 4.0 CollectionViewSource with WCF RIA Services
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2010-07-19

    Table of Contents:
  • Silverlight 4.0 CollectionViewSource with WCF RIA Services
  • CollectionViewSource in Siverlight: code explained
  • How to filter data in CollectionViewSource using Siverlight
  • How to filter data in CollectionViewSource using Siverlight: code explained

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Silverlight 4.0 CollectionViewSource with WCF RIA Services


    (Page 1 of 4 )

    This article introduces the “CollectionViewSource” element available in Silverlight (using WCF RIA Services) and also discusses applying filters to existing data using “CollectionViewSource.”

    To make this article simple, I managed to create a simple Silverlight 4.0 application which consumes a WCF RIA Service created using the WCF RIA Service Library.  If you are not familiar with developing applications using the WCF RIA Service Library and Silverlight 4.0, check out a beginner’s article available at http://jagchat.spaces.live.com/blog/cns!41050F68F010A662!4439.entry.

    The solution was developed using Microsoft Visual Studio 2010 Ultimate Edition with Microsoft Silverlight 4.0 on Windows 7 Ultimate edition. I didn’t really test it in any other environment. I request that you post in the discussion area if you have any problems with execution.

    Working with CollectionViewSource in Siverlight

    Using a WCF RIA Service, we can somehow bring data down to a Silverlight application. Once the data is available to the Silverlight application, we may want to have it be viewed in different logical ways (such as a sorted view, filtered view etc.). “CollectionViewSource” is mainly designed to have view-like scenarios against the data already available in Silverlight. Not only that, but we can also track and work with the “current” item. We will discuss these soon.

    Let us start with an example.

    <UserControl x:Class="SLBusinessAppWithRiaLib.CvsBasic"

     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

     mc:Ignorable="d"

     d:DesignHeight="300" d:DesignWidth="400"

     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" Width="500" Height="500">

     <UserControl.Resources>

     <CollectionViewSource x:Key="cvsEmp"/>

     </UserControl.Resources>

     

     <Grid x:Name="LayoutRoot" Background="White">

     <Grid.RowDefinitions>

     <RowDefinition Height="*" />

     </Grid.RowDefinitions>

     

     <sdk:DataGrid 

     x:Name="dgEmp"

     Margin="8" MinHeight="200" IsReadOnly="True" />

     

     </Grid>

    </UserControl>

    The above code contains the declarations for a “DataGrid” and “CollectionViewSource.” You should also note that “CollectionViewSource” is defined in the “Resources” of the Silverlight user control (or page). At this point, we have not brought any data to Silverlight yet. Also, “DataGrid” and “CollectionViewSource” in the above code are not related to each other (we bind them in code).

    Let us modify the code behind as follows:

    Imports System.ServiceModel.DomainServices.Client

    Imports System.Windows.Data

     

    Partial Public Class CvsBasic

    Inherits UserControl

     

    Private oCtxt As New BusinessLib.Web.EmpMgrDomainSvc

    Private oCvsEmp As CollectionViewSource

     

    Public Sub New()

    InitializeComponent()

     

    oCvsEmp = CType(Me.Resources("cvsEmp"), CollectionViewSource)

    oCvsEmp.Source = oCtxt.emps

    oCtxt.Load(oCtxt.GetEmpsQuery())

    Me.dgEmp.ItemsSource = oCvsEmp.View

     

    End Sub

     

    End Class

    The next section explains the above code.

    More Silverlight Articles
    More By Jagadish Chaterjee


       · Hi guys,This is my next article on Silverlight 4.0 focusing on working with...
     

    SILVERLIGHT ARTICLES

    - Silverlight 4.0: Navigating Data Using Domai...
    - Silverlight 4.0: Filtering Data Using Domain...
    - Silverlight 4.0: Sorting and Grouping Data w...
    - Silverlight 4.0: Query Parameters of DomainD...
    - Silverlight 4.0: DomainDataSource
    - Silverlight 4.0: Grouping and Sorting using ...
    - Silverlight 4.0 Data Manipulation and Naviga...
    - Silverlight 4.0 CollectionViewSource with WC...
    - Silverlight 4.0 Data Manipulation Using WCF ...
    - Silverlight 4.0 Data Retrieval: Getting Data...
    - Painting with ImageBrush, VideoBrush and Web...
    - Using RadialGradientBrush in Silverlight 4.0
    - Complete Guide to Gradients Using LinearGrad...
    - Introduction to Brushes in Silverlight 4.0
    - Data Conversion with Silverlight 3





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek