Application Development Tips with Silverlight 4 Tools

Application Development Tips with Silverlight 4 Tools

Silverlight is a great tool that you can use to work with data retrieved from different services. With some knowledge of asynchronous programming and callbacks, you can use Silverlight to develop applications that are bound to data retrieved from different services that can scale over time. This article presents a brief overview of WCF and Silverlight and discusses how they can be used in application development to design and implement applications that can scale over time with intuitive user interfaces.

Pre-Requisites

To work with Silverlight 4 and Windows Communication Foundation 4 you should have the following installed in your system:

[login]

  • Visual Studio 2010
  • Silverlight 4 Tools for Microsoft Visual Studio 2010

To take advantage of the concepts discussed in this article, you should be familiar with all of the following:

  • Microsoft Visual Studio 2010
  • C# Programming Language
  • .NET Framework 4.0
  • Basic knowledge of Silverlight and/or WPF

Introducing Windows Communication Foundation (WCF)

Windows Communication Foundation (WCF) is a platform that can be used to design and implement platform independent, scalable services and provides support for unification of a number of enterprise technologies under one roof. The MSDN states, “Windows Communication Foundation (WCF) is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.” Reference: http://msdn.microsoft.com/en-us/library/ms735119.aspx

Note that WCF was introduced as part of .NET Framework 3.0 in 2006 and was initially named “Indigo”. WCF 4 is now available as part of Visual Studio 2010.

Windows Communication Foundation 4.0 includes a lot of interesting new features. These include:

  • Support for Simplified Configuration
  • Support for Standard Endpoints
  • Support for Discovery
  • Support for Simplified IIS Hosting
  • Enhanced Support for REST
  • Support for Routing service
  • Support for Workflow services

Silverlight 4 — A Quick Look

Silverlight is a browser plug-in that promotes a collaborative development environment of rich online media content that enables developers and designers alike to integrate multimedia and graphics into web pages within the context of the managed environment. Over the past few years, Silverlight, formerly known as Windows Presentation Foundation Everywhere (WPF/E), has become popular worldwide for developing the next generation of cross-browser, cross-platform Rich Internet Applications (RIAs).

Silverlight 4 provides a lot of interesting new features that help developers to build cutting edge applications with awesome multimedia and graphics. You now have support for printing, rich reporting and charting, support for web camera and microphone, support for COM automation, support for local file access, support for new languages, rich text editing, and, improved support for data binding to name a few.

Data binding Silverlight 4 Controls using WCF

Data binding is a term that implies binding data retrieved from a data source to data controls. You can use WCF Data Services to create and consume OData services for the web seamlessly. Microsoft states: “The Open Data Protocol, referred to as OData, is a new data-sharing standard that breaks down silos and fosters an interoperative ecosystem for data consumers (clients) and producers (services) that is far more powerful than currently possible. It enables more applications to make sense of a broader set of data, and helps every data service and client add value to the whole ecosystem.” Reference: http://msdn.microsoft.com/en-us/data/aa937697

WCF Data Services (previously known as ADO.NET Data Services), provides support for the Open Data Protocol in a managed environment. To bind data to Silverlight 4 controls using WCF, you should follow the steps outlined below:

  1. Create a new application in Visual Studio 2010.
  2. Select the project you have created in the solution explorer and click “Add New Item”
  3. Select ADO.NET Entity Data Model from the list of the project templates displayed
  4. Specify the data connection as needed and select the AdventureWorks database
  5. To expose the data retrieved through the Entity Data Model for the AdventureWorks database, create a new WCF Data Service
  6. Configure your data service accordingly so that it can be used to pull data out of the AdventureWorks database

Your data service code would look like as shown in the code snippet below:

public class MyDataService : MyDataService{ ??public static void InitializeService(DataServiceConfiguration config) ??{ ?????config.SetEntitySetAccessRule("*", EntitySetRights.All); ?????config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; ??}}

  1. Next, create a new Silverlight 4 application and add the service reference to it.
  2. Create a Grid and then use the service reference to bind data to the Silverlight Grid.
  3. Lastly, build and execute the project

That's it!

Data-binding Improvements in Silverlight 4

Before Silverlight 4, to bind data, you were restricted to have the object (that would be used to bind data) derive from the FrameworkElement class. With Silverlight 4, you can now bind data using any object that is inhertited from DependencyObject.

Silverlight 4 introduces some other interesting new improvements in DataBinding. These include:IDataErrorInfo support, string formatting support, TargetNullValue, FallbackValue support, etc.

The following code snippet shows how String formatting can be used while binding data in Silverlight 4 controls:

You can use TargetNull value while data binding to Silverlight 4 controls if the element can contain a null value. You can use FallbackValue if no data is available to bind to the data control. The following code snippet shows how TargetNull and FallbackValue can be used:

Suggested Reading

Here are a few links to that provide further references on this topic:

http://www.microsoft.com/silverlight/

http://www.silverlight.net/getstarted/silverlight-4/

http://www.silverlight.net/learn/tutorials/silverlight-4/using-wcf-ria-services/

http://msdn.microsoft.com/en-us/library/ee354381.aspx

http://msdn.microsoft.com/en-us/library/ee621313.aspx

http://wildermuth.com/2009/11/18/Data_Binding_Changes_in_Silverlight_4

http://msdn.microsoft.com/en-us/data/bb931106

http://msdn.microsoft.com/en-us/data/aa937697

Summary

Windows Communication Foundation is a Microsoft framework that can be used to develop scalable, service oriented, REST-based services. There have been quite a few enhancements in WCF 4.0 that has eliminated the pain of specifying tedious configuration details to host services. In this article we have discussed the basics of WCF and Silverlight and how we can use WCF data services to bind data to Silverlight controls. Happy reading!

devx-admin

devx-admin

Share the Post:
Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically

Innovation Ignition

New Fintech Innovation Ignites Change

The fintech sector continues to attract substantial interest, as demonstrated by a dedicated fintech stage at a recent event featuring panel discussions and informal conversations with industry professionals. The gathering,

Import Easing

Easing Import Rules for Big Tech

India has chosen to ease its proposed restrictions on imports of laptops, tablets, and other IT hardware, allowing manufacturers like Apple Inc., HP Inc., and Dell Technologies Inc. more time

Semiconductor Stock Plummet

Dramatic Downturn in Semiconductor Stocks Looms

Recent events show that the S&P Semiconductors Select Industry Index seems to be experiencing a downturn, which could result in a decline in semiconductor stocks. Known as a key indicator

Anthropic Investment

Amazon’s Bold Anthropic Investment

On Monday, Amazon announced its plan to invest up to $4 billion in the AI firm Anthropic, acquiring a minority stake in the process. This decision demonstrates Amazon’s commitment to

AI Experts Get Hired

Tech Industry Rehiring Wave: AI Experts Wanted

A few months ago, Big Tech companies were downsizing their workforce, but currently, many are considering rehiring some of these employees, especially in popular fields such as artificial intelligence. The

Lagos Migration

Middle-Class Migration: Undermining Democracy?

As the middle class in Lagos, Nigeria, increasingly migrates to private communities, a PhD scholar from a leading technology institute has been investigating the impact of this development on democratic

AI Software Development

ChatGPT is Now Making Video Games

Pietro Schirano’s foray into using ChatGPT, an AI tool for programming, has opened up new vistas in game and software development. As design lead at business finance firm Brex, Schirano

Llama Codebot

Developers! Here’s Your Chatbot

Meta Platforms has recently unveiled Code Llama, a free chatbot designed to aid developers in crafting coding scripts. This large language model (LLM), developed using Meta’s Llama 2 model, serves

Tech Layoffs

Unraveling the Tech Sector’s Historic Job Losses

Throughout 2023, the tech sector has experienced a record-breaking number of job losses, impacting tens of thousands of workers across various companies, including well-established corporations and emerging startups in areas

Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G technology by local network providers

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to transform the way modern warfare

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI detection software, such as Turnitin’s

US Commitment

US Approves Sustainable Battery Research

The US Department of Energy has revealed a $325 million commitment in the research of innovative battery types, designed to enable solar and wind power as continuous, 24-hour energy sources.

Netanyahu Musk AI

Netanyahu and Musk Discuss AI Future

On September 22, 2023, Israeli Prime Minister Benjamin Netanyahu met with entrepreneur Elon Musk in San Francisco prior to attending the United Nations. In a live-streamed discussion, Netanyahu lauded Musk