We'll also guide you through the required tools and installations for a perfect Silverlight development environment.
Silverlight was released in the first half of , and since then, it has created a lot of buzz. While ASP. NET is a server-side development platform, with the arrival of Silverlight, the focus has shifted to the client side again. A big benefit for developers is that Silverlight uses. NET from version 2 onwards. Because of the similarities, many skills achieved from developing applications in the full.
NET framework can be leveraged for the creation of Silverlight applications. Silverlight itself can be considered as a trimmed-down version of its desktop counterpart, Windows Presentation Foundation WPF.
Between Silverlight 4 and WPF 4, there are still some differences. Some features are included in WPF 4, but aren't in Silverlight 4 and vice versa. It's possible to reuse code written for one technology in the other. However, upfront planning is required to ensure a smooth transition between the two technologies. Microsoft has released a whitepaper based on this aspect that provides more information on how to write applications that target both Silverlight and WPF.
With the release of Silverlight 2, Microsoft made it clear that Silverlight is aimed at both creating rich and interactive applications, and next-level enterprise applications in the browser. The latter can be easily seen with the addition of a rich control set, support for many types of services and platform features such as data binding. Due to its client-side characteristics, Silverlight applications need to perform particular tasks to get data.
It doesn't support client-side databases—not even in version 4. The way to retrieve data is through services. Silverlight 3 brought some interesting features to the platform in this area such as support for binary XML, the WCF RIA services, and simplified duplex service communication.
Silverlight 4 continued in the same manner, with improvements in data binding, support for net. All these added features are a proof of the commitment Microsoft is making to position Silverlight as a platform for building enterprise applications. In this chapter, we'll get you up and running with Silverlight. While this book is aimed at developers who already have a basic knowledge of Silverlight, this chapter can act as a refresher. We'll also look at getting your environment correctly set up so that you enjoy developing Silverlight applications.
In this recipe, we'll look at what we need to install to start developing Silverlight applications. We'll learn about the basic tools that we need as a developer and also take a look at the designer tools that can come in handy for developers as well. To start developing Silverlight applications, we'll need to install the necessary tools and SDKs.
Carry out the following steps in order to get started:. Open Visual Studio after installation. Visual Studio ships with Silverlight 3 templates installed out of the box, the tools add support for version 4.
For Silverlight development, the minimum that we need are the developer tools. These will integrate with Visual Studio if you're using Silverlight 3 or In the version, this designer doesn't exist. When installing the developer tools for Silverlight 4, the following components are automatically downloaded and installed:. However, if you're serious about designing, you might want to consider using Microsoft Expression Blend.
This tool, primarily aimed at designers, should be seen as an application that generates XAML for us by means of a rich number of options and an easy-to-use interface. It also integrates nicely with Visual Studio and source control software integration is available as well.
After having installed all the necessary tools, it might be worth taking a look at the Creating our first service-enabled and data-driven Silverlight 4 application using Visual Studio recipe as well as the Using the workflow between Visual Studio and Blend 4 recipe.
In these recipes, we create an entire application in Visual Studio and Blend 4 respectively. In this recipe, we'll build a very simple Silverlight application that uses techniques that are explained in much more detail later on in the book.
We'll be using data binding , which is a technique to easily connect data to the user interface UI and connect to a Windows Communication Foundation WCF service. However, the main goal is to get a grip on the basics of Silverlight by trying to answer questions such as how a Silverlight application is built, what the project structure looks like, what files are created, and what is their use.
To get started with Silverlight application development, make sure that you have installed Visual Studio along with the necessary tools and libraries as outlined in the previous recipe. We are building this application from the ground up. Our first Silverlight application allows the user to view the details of a hotel that is selected in a ComboBox control.
The hotel information is retrieved over a service and is used for filling the ComboBox and the details shown in several TextBlock controls that are placed in a grid. Open Visual Studio with the Silverlight 4 tools installed. In the dialog that appears as shown in the next screenshot, select ASP. Also, make sure that Silverlight 4 is selected as the target version of Silverlight 4. After Visual Studio has finished executing the project template, two projects are created in the solution: the Silverlight project and a web application project that is responsible for hosting the Silverlight content.
The created solution structure can be seen in the following screenshot:. Our service will return the hotel information. A hotel can be represented by an instance of the Hotel class. This class should be included in the web project— SilverlightHotelBrowser. This class has a DataContract attribute attached to it. This attribute is required to specify that this class can be serialized when sent over the wire to the client application.
Each property is attributed with the DataMember attribute. When adding this attribute to a property, we specify that this property is a part of the contract and that it should be included in the serialized response that will be sent to the client.
We'll now add a WCF service to the web project as well. Right-click on SilverlightHotelBrowser. Web and select Add New Item Click the Add button. Two files are added, namely, HotelService. In this service class, we can now add a method that returns a hardcoded list of hotels.
Remove the DoWork method and replace it with the following code:. Note the attributes that have been used in this class. The ServiceContract attribute specifies that the class contains a service contract that defi nes what functionality the service exposes.
The OperationContract attribute is added to operations which can be invoked by clients on the service. This effectively means that if you add methods to the service without this attribute, it can't be invoked from a client. Now we'll build the solution and if no errors are encountered, we're ready for takeoff—takeoff for writing Silverlight code. Let's first make the service known to the Silverlight application.
Right-click on the Silverlight application and select Add Service Reference In the dialog box that appears, as shown in the following screenshot, click on Discover and select your service. As it is in the same solution, the service will appear. Enter HotelService in the Namespace field.
The UI was shown earlier and is quite easy. In the code-behind class, MainPage. We won't focus here on what's actually happening with the service call and the data binding; all this is covered in detail later in this book.
We will compile the solution again and then press the F5 button. The application should now run, allowing us to select a hotel in the ComboBox. Each selection change will trigger an event that shows the details of the selected item using data binding.
Silverlight applications always have to run in the context of the browser. That's the reason why Visual Studio prompts us initially by asking how we want to host the Silverlight content.
Note that Silverlight 3 added out-of-browser capabilities to its previous version, thereby allowing Silverlight applications to run "standalone". However, they still run inside the browser sandbox.
Silverlight 4 added the option to run a Silverlight application out of browser with elevated permissions, thereby giving it more permissions on the local system.
We'll be looking at these later on in this book. The default option is the ASP. This option gives us the maximum number of possibilities for the configuration of the host project. It's the option that we will be using the most throughout this book because of the configuration options it offers towards working with services. The second option is ASP. NET 2.
Finally, we can also uncheck the Host the Silverlight application in a new Web site checkbox. This option is not well suited for building Silverlight applications that work with services as we have no control over the generation process.
A new Silverlight solution thus contains normally two projects—a Silverlight project and a hosting application. NET files, among others. By default, one page is added for free—called MainPage. It's not really a page, but a user control that is hosted. We can add UI code such as controls, grids, and so on to this file. We add UI logic in the code-behind. One special case is the App. It's the entry point of an application and is responsible for loading an instance of the MainPage , executing logic when an error occurs, and so on.
Also, it can contain global resources such as styles that should be available over the entire application. Your book made it to my short list along with the Cameron Albert book. I am looking for something that shows me how to preferably use RIA but not constrain me to EF as I have a custom lower level hard core ado.
Thanks Kevin, I do not need change tracking so sounds like I do not need RIA which is fine with me as long as I dont conflict with requirements of Telerik so I am making a post over there.. I was impressed with this book because it showed you how to create a web service, business layer, data layer finally real n tier programming!! YOU did an excellent in showing the real basics!!
The only way this book would be better if you would have used M-V-VM and prism. I have a feeling someone would tackle this in silverlight 5!! The content you requested has been removed. Ask a question. Quick access. Search related threads. Remove From My Forums. Answered by:. Archived Forums. Programming Silverlight with. NET — General. NET applications. Sign in to vote. Wonderful article, thanks for putting this together! Thanks for the valuable information and insights you have so provided here.
Keep it up! Thank God! Your blogs are there to provide us the pile of useful information. Took my time to read all the comments, but I enjoyed the article. After reading your article I can say that you have good writing skills.
I will tell my friends about your website. I will come again to read new articles. Your website is very useful. People will learn a lot from it.
0コメント