Blue Theme Orange Theme Green Theme Red Theme
 
Ads by Lake Quincy Media
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Silverlight » Progressbar control in Silverlight 3.0

Progressbar control in Silverlight 3.0

In this article, I will explain couple of things step by step. First how to work with Progressbar control of Silver Light 3.0.Then how to consume WCF service in Silverlight application when both are in same solution.

Author Rank:
Total page views :  1482
Total downloads :  48
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
TestingProgressBar.zip
 
Become a Sponsor


Objective

In this article, I will explain couple of things step by step 

  1. How to work with Progressbar control of Silverlight 3.0
  2. How to consume WCF service in Silverlight application when both are in same solution.
Step 1

Create a Web Application. Give any name of your choice. I am giving name here TestingProgressBar. 

1.gif

Step 2

Right click on Web Application project and Add new Item.  Go to Silverlight category and choose Silverlight-enabled WCF Service project template.  Give any name of your choice. I am leaving the defualt name Service1.svc

2.gif

Step 3

Write the service. Service is returning a List of Authors. Author is class with properties Name and Article. Service method having very simple functionality, where a list of Author is getting construed and returned.

Service1.svc.cs

using
System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;

namespace
TestingProgressBar
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        [OperationContract]
        public List<Author> DisplayAuthor()
        {
            List<Author> result = new List<Author>();
            result.Add(new Author() { Name = "Dhananjay Kumar ", Articles = "100" });
            result.Add(new Author() { Name = "Anoj Pillai ", Articles = "1000" });
            result.Add(new Author() { Name = "Arun Gopal V ", Articles = "50" });
            result.Add(new Author() { Name = "Mubarag Ali  ", Articles = "500" });
            result.Add(new Author() { Name = "Dipti Maya Patra ", Articles = "100" });
            result.Add(new Author() { Name = "Raj KUmar G ", Articles = "300" });
            result.Add(new Author() { Name = "Prajith P  ", Articles = "10" });
            result.Add(new Author() { Name = "Mahesh Chand  ", Articles = "400" });
            result.Add(new Author() { Name = "VRave ", Articles = "1000" });
            result.Add(new Author() { Name = "Mike Gold ", Articles = "1000" });
            result.Add(new Author() { Name = "Jessy Liberty  ", Articles = "1400" });
            result.Add(new Author() { Name = "Nithin Kothari", Articles = "600" });
            result.Add(new Author() { Name = "Tim Huer", Articles = "1000" });
            result.Add(new Author() { Name = "Jag  ", Articles = "1000" });
            result.Add(new Author() { Name = "David Paul Prem Kumar", Articles = "100" });
            result.Add(new Author() { Name = "Dhilip Sitara ", Articles = "1000" });
            result.Add(new Author() { Name = "web Blog", Articles = "700" });
            return result;
 
        }
    }

    [DataContract]

    public class Author

    {

        [DataMember]

        public String Name { get; set; }

        [DataMember]

        public String Articles { get; set; }

    }

}

Step 4

Build the web application project.  After successfully compilation right click on service and view in browser to check service is running successfully or not. 

3.gif

You should get the below output in browser. If you getting below output, it means you have successfully created the service and it is running.  If you are not getting below output again cross check the previous said steps. 

4.gif

Step 5

Right click on solution and add new Silverlight application type project.  Go to Silverlight category and choose Silverlight Application project template.  Give any name, I am leaving here default name i.e. SilverLightApplication1.

5.gif

Host the SilverLightApplication1 in existing Web Application in solution.  We created this web application TestingProgressbar in step 1. 

6.gif

Step 6

Design the Silverlight page.  Add one button like below

<
UserControl x:Class="SilverlightApplication1.MainPage"

    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:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot">

        <Grid.RowDefinitions>

            <RowDefinition Height="*"/>

            <RowDefinition Height="*" />

        </Grid.RowDefinitions>

        <Button x:Name="myButton" Height="100" Width="300" Click="myButton_Click"   Content="Click Me"  Grid.Row="0"/>

    </Grid>

</UserControl>

In above XAML, drag and drop one DataGrid and Progress Bar just below Button control.   To open the tool box, from Menu select View and Tool Box. After dragging and drop modify the XAML for DataGrid and ProgressBar as below.

<
data:DataGrid x:Name="myGrid" AlternatingRowBackground="Aqua" Grid.Row="1" Visibility="Collapsed"/>
       <ProgressBar x:Name="myProgressbar" Width="400" Height="100" Grid.Row="1" Visibility="Collapsed"/>

Step 7

Add the service reference. To add right click on reference in Silverlight application and select add Service Reference. From window click on Discover, this will discover the service in the solution.  Give any name for the service reference; I am leaving the default name.

7.gif

Step 8

Add property to handle the Progress Bar. This is Boolean property. This is using IsIndeterminate property of Silverlight progress bar control.  We are setting progress bar Boolean property .

public
bool IsWorking
{
    get { return  myProgressbar.IsIndeterminate; }
    set { myProgressbar.IsIndeterminate = value; }
}

Step 9

On Button click event, I am creating a proxy of service and just handling the Completed event and calling the Async method.  In other work, I am just hiding and displaying the progress bar and grid view.  After calling the Async method I am making IsWorking property true.

private
void myButton_Click(object sender, RoutedEventArgs e)

{

    myGrid.Visibility = Visibility.Collapsed;

    myProgressbar.Visibility = Visibility.Visible;

    Service1Client proxy = new Service1Client();

    proxy.DisplayAuthorCompleted += new EventHandler<DisplayAuthorCompletedEventArgs>(proxy_DisplayAuthorCompleted);

    proxy.DisplayAuthorAsync();

    this.IsWorking = true;

}

Step 10

On completed event, I am assigning item source of datagrid as e.reult.  In other work just making IsWorking property as false. And Hiding the progress bar and displaying the datagrid.

void
proxy_DisplayAuthorCompleted(object sender, DisplayAuthorCompletedEventArgs e)

{

    this.IsWorking = false;

    myProgressbar.Visibility = Visibility.Collapsed;

    myGrid.Visibility = Visibility.Visible;

    myGrid.ItemsSource = e.Result;

}

Note for cross Domain issue

Since in our sample, both Silverlight application and WCF service is in same solution then there is no cross domain issue will come. But even if you are getting cross domain issue make sure of below things 

  1. Make Startup project to Web Application Project. Right Click on Web Application Project and make it as startup project.
  2. Make SilverLightApplication1.aspx page as start up page.  
Output

On clicking of button, service will get called and progress bar will show the waiting. After that  Datagrid will get populated with the data. 

8.gif

9.gif

10.gif

Complete code is available in the source code attached with this article.

Conclusion

In this article, I explained how to consume WCF service in Silverlight application when both are in same solution.  I also explained how to work with Progressbar control in Silverlight 3.0. Thanks for reading.


Login to add your contents and source code to this article
 About the author
 
Dhananjay Kumar
I am Dhananjay Kumar. I passed computer science  & engineering from AEC Agra in year 2007. I born and brought up in Jamshedpur , Jharkhand.I am MCTS on WCF, MOSS Development , .Net Framework 2.0 Web Application so far. I read and write on WCF, SilverLight , SharePoint , ASP.Net MVC, ASP.Net 3.5 Extensions , .Net 4.0 , C# 3.0 , C# 4.0 etc etc. Currently , I am working for UST Global as Software Engineer and active member of Microsoft COE team .
 
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
TestingProgressBar.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.