Pro Business Applications with Silverlight 4
®
THE EXPERT’S VOICE
IN SILVERLIGHT
Pro Business Applications with
Silverlight 4 Create rich business applications customized to your needs quickly and efficiently
Chris Anderson
Pro Business Applications with Silverlight 4 Chris Anderson
Pro Business Applications with Silverlight 4
Copyright © 2010 by Chris Anderson All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-4302-7207-6
ISBN-13 (electronic): 978-1-4302-7206-9 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
President and Publisher: Paul Manning Lead Editor: Jon Hassell Technical Reviewer: Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell,
Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Coordinating Editor: Tracy Brown Copy Editors: Julie Hammond, Damon Larson, Heather Lang, Kim Wimpsett. Compositor: Bytheway Publishing Services Indexer: Toma Mulligan Artist: April Milne Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th
For information on translations, please e-mail Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing we The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at d to answer questions pertaining to this book in order to successfully download the code.
For my grandmother Connie, a great role model for will power, optimism, generousity, patience, and love. I miss her dearly.
Contents at a Glance Contents at a Glance .............................................................................................. About the Author..................................................................................................
Chapter 1: Introduction...........................................................................................
Chapter 2: Getting Started with Silverlight...........................................................
Chapter 3: An Introduction to XAML .....................................................................
Chapter 4: The Navigation Framework .................................................................
Chapter 5: Exposing Data from the Server: Using WCF RIA Services....................
Chapter 6: Implementing Summary Lists ...........................................................
Chapter 7: Building Data Entry Forms ................................................................
Chapter 8: Securing Your Application.................................................................
Chapter 9: Styling Your Application....................................................................
Chapter 10: Advanced XAML and Data Binding ..................................................
Chapter 11: Creating Custom Controls ...............................................................
Chapter 12: The Model-View-ViewModel (MVVM) Design Pattern......................
Chapter 13: Printing and Reporting ....................................................................
Chapter 14: Out of Browser Mode, and Interacting with the Operating System ...............................................................................................
Chapter 15: Application Deployment .................................................................. Index ...................................................................................................................
Contents Contents at a Glance .............................................................................................. About the Author..................................................................................................
Chapter 1: Introduction...........................................................................................
Chapter 2: Getting Started with Silverlight...........................................................
CONTENTS
Silverlight 4 Tools ................................................................................................................................... Silverlight Toolkit.................................................................................................................................... Silverlight Spy (and .NET Reflector)........................................................................................................
Creating a Silverlight Application ....................................................................................
Silverlight Application............................................................................................................................. Silverlight Business Application ............................................................................................................. WCF RIA Services Class Library..............................................................................................................
Running and Exploring the Default Silverlight Business Application Project...................
Project Links........................................................................................................................................... The Silverlight Application Project Structure..........................................................................................
Recommended Project Template Modifications ..............................................................
XAP Files..........................................................................................................................
Chapter 3: An Introduction to XAML .....................................................................
CONTENTS
Attached Properties ................................................................................................................................
XAML Namespace Properties ................................................................................................................. Markup Extensions .................................................................................................................................
Controls ........................................................................................................................... Base Control Classes ..............................................................................................................................
XAML vs. Windows Forms Controls’ Property Names ............................................................................ Creating a Simple User Interface............................................................................................................
Resources and Resource Dictionaries ............................................................................. Templates ........................................................................................................................
Binding to an Object ............................................................................................................................... Designing User Experiences ............................................................................................
XAML User Interfaces: A Different Perspective................................................................
Chapter 4: The Navigation Framework .................................................................
CONTENTS
Navigating Between Views ..............................................................................................
View URIs................................................................................................................................................ Navigation Methods on the NavigationService Object............................................................................ Using the Source Property of the Frame Control ....................................................................................
Passing Data Between Views ..........................................................................................
Passing Data Using Query String Parameters ........................................................................................ Passing Complex Data Types Between Views ........................................................................................
Deep Links .......................................................................................................................
Integrating with the Browser History...............................................................................
Frame Events..........................................................................................................................................
Caching Views .................................................................................................................
Alternative User Interface Frameworks ...........................................................................
Chapter 5: Exposing Data from the Server: Using WCF RIA Services....................
CONTENTS
Consuming the Domain Services............................................................................................................ Getting Started................................................................................................................
Configuring the Database ..................................................................................................................... Creating an Entity Model ......................................................................................................................
Domain Services............................................................................................................ Understanding the Domain Service Life Cycle......................................................................................
Domain Operations ........................................................................................................ Query Operations.................................................................................................................................. Invoke Operations.................................................................................................................................
Decorating Entities ........................................................................................................ Metadata Classes ................................................................................................................................. Validation.............................................................................................................................................. Miscellaneous Data Annotations ..........................................................................................................
Presentation Model Types ............................................................................................. Creating the Presentation Model Class................................................................................................. Updating Your Presentation Model Types.............................................................................................
Sharing Code/Logic Across Tiers................................................................................... Encapsulating Logic in a Separate WCF RIA Services Class Library..............................
CONTENTS
Handling Data Concurrency Violations.
Methods of Identifying Concurrency Violations . .................................................................................. Testing Your Solution .
Transactions ..................................................................................................................
Alternative Communication Technologies .
WCF Services. HTTP Requests .
Summary .......................................................................................................................
Chapter 6: Implementing Summary Lists .
CONTENTS
Choosing the Right Control ................................................................................................................... Manipulating Summary Lists .........................................................................................
Querying Data Exposed by a Domain Operation ................................................................................... Sorting the Summary List..................................................................................................................... Paging the Summary List .....................................................................................................................
Drilling Down on a Record ............................................................................................. Opening Details in a New View............................................................................................................. Displaying Details Using the DataGrid’s Row Details ...........................................................................
Handling Errors ..............................................................................................................
Chapter 7: Building Data Entry Forms ................................................................
CONTENTS
Notifying the User Interface of Object-Level Validation Errors ............................................................. Customizing Validation Attribute Error Messages ................................................................................
Submitting Changes to the Server.................................................................................
Change-Tracking .................................................................................................................................. Submitting Changes via a Domain Context .......................................................................................... Handling Concurrency Violations..........................................................................................................
Summary .......................................................................................................................
Chapter 8: Securing Your Application.................................................................
CONTENTS
Cross-Domain Access Policies ...................................................................................... Implementing Cross-Domain Policies for HTTP-Based Communication............................................... Implementing Cross-Scheme Access Policies .....................................................................................
Restricting Access to Your Application ..........................................................................
Chapter 9: Styling Your Application....................................................................
CONTENTS
Summary .......................................................................................................................
Chapter 10: Advanced XAML and Data Binding ..................................................
Chapter 11: Creating Custom Controls ...............................................................
CONTENTS
Exposing Events ................................................................................................................................... Constraining the User Control’s Size ....................................................................................................
Creating Custom Controls .............................................................................................. Creating the Custom Control ................................................................................................................ Defining the Control’s Default Template...............................................................................................
Content Controls ............................................................................................................ Containing a Single Control as Content ................................................................................................ Attached Properties ..............................................................................................................................
Summary .......................................................................................................................
Chapter 12: The Model-View-ViewModel (MVVM) Design Pattern......................
CONTENTS
Implementing the View.........................................................................................................................
Frameworks...................................................................................................................
Chapter 13: Printing and Reporting ....................................................................
Chapter 14: Out of Browser Mode, and Interacting with the Operating System ...............................................................................................
CONTENTS
Debugging Out of Browser ................................................................................................................... Toast Notifications................................................................................................................................
Caching Data Locally ..................................................................................................... Caching to Isolated Storage.................................................................................................................. Detecting Network Connection Availability ..........................................................................................
File System Open/Save Dialogs ..................................................................................... The Open File Dialog.............................................................................................................................
Drag Drop Target ........................................................................................................... Full Screen.....................................................................................................................
Initiating Full Screen Mode................................................................................................................... Retaining Full Screen Mode When Unfocused......................................................................................
Elevated Trust................................................................................................................ Enabling Elevated Trust........................................................................................................................ COM Automation................................................................................................................................... Other Restrictions Lifted By Elevated Trust .......................................................................................... Disabling Elevated Trust Applications with a Windows Group Policy...................................................
Summary .......................................................................................................................
Chapter 15: Application Deployment ..................................................................
CONTENTS
Server Requirements............................................................................................................................ Publishing............................................................................................................................................. Creating a Setup Program ....................................................................................................................
Deploying the Application to the Client..........................................................................
The Default Silverlight Installation Process .......................................................................................... Pushing the Silverlight Runtime to Users in the Enterprise..................................................................
Improving on the Default Application Loading Screen...................................................
Creating the Application Pre-loader Files............................................................................................. Updating the Application Download Progress ...................................................................................... Testing the Application Pre-loader .......................................................................................................
Partitioning Your Application .........................................................................................
Initial Steps........................................................................................................................................... Downloading Modules on Demand .......................................................................................................
Digitally Signing Your Application..................................................................................
Index ...................................................................................................................
About the Author Chris Anderson has been a professional developer for over 10 years, specializing in building desktop,
web, and mobile business applications using Microsoft technologies for industries as wide ranging as accounting, property valuation, mining, the fresh produce industry, logistics, field services, sales, and construction. He holds a Bachelor of Engineering in Computer Systems with a Diploma in Engineering Practice.
Chris is now a co-owner of Peer Placements (a specialist recruitment firm for software developers), in addition to working as a consultant, author, and Australian representative of the SilverlightShow.net website. Currently specializing in Silverlight Chris has spoken on this topic at conferences such as Code Camp Australia, TechEd Australia, Silverlight Code Camp Australia, REMIX Australia, and numerous Sydney Silverlight Designer and Developer Network (SDDN) meetings (for which he is a co-organizer).
nd on Twitter at
Chris maintains a blog at
Acknowledgments
I had no idea what I was getting into when taking on this book. Writing a book is a long, arduous task that consumes your entire life, but now that this book is complete I would like to thank those who were instrumental in helping it come to fruition.
I’d like to start by thanking the members of the Apress team with whom I worked closely throughout the writing process. I’m grateful for their guidance and encouragement. I’d like to thank Jonathon Hassell and Anne Collett, and in particular Tracy Brown, who was extremely patient with me even as deadlines were rapidly approaching. My great thanks also go to my technical editor Ilia Iordanov, who, with an eagle eye, spotted many issues I had missed, and made some great suggestions.
who gave his time to review every
I would especially like to thank Greg Harris (
chapter in its draft form, and who provided me with extensive feedback. I really appreciate the amount of time and effort Greg voluntarily spent on this project. His contributions are invaluable. I would also like to thank Miguel Madero and Pencho Popadiyn, who provided additional valuable feedback on the Model-View-ViewModel Design Pattern chapter, and Sergey Klementiev for providing a solution to a problem I had with RIA Services. My thanks also go to all the Silverlight bloggers who provided solutions to difficult problems. I’ve credited you in the text when you’ve provided information that helped me along my way.
From a personal perspective, I’d really like to thank my sister Michelle, chef extraordinare, for providing me with home-cooked frozen meals that kept me decently fed for a month when I was working furiously on this book and barely leaving the house. It was a huge help. I’d also like to thank Mark Wallis, who covered for me with my clients whilst I had my head down writing. I hope they’ll forgive my absence.
C H A P T E R 1 Introduction
Silverlight is a web-based platform from Microsoft that can be used to build rich Internet applications (RIAs). Of the many new possibilities it enables, one receiving a lot of attention is its huge potential as a platform for building business applications. Despite its relative youth (having just reached its third birthday), it has achieved remarkable maturity, with its development progressing at a rapid rate—now at version 4. With just nine months separating versions 2 and 3, and a further nine months separating versions 3 and 4, its tremendous growth in that short time demonstrates the enormous amount of effort and commitment that Microsoft is pouring into Silverlight to bring it to the forefront as one of its core development platforms. Community support for the technology has been overwhelmingly positive, gaining more and more momentum as companies increasingly choose it over more mature platforms.
This ensures its future as a viable platform for delivering applications that you can be sure will only grow and become ever more popular.
If you have previously only been exposed to Windows Forms and ASP.NET development, then it will no doubt be a brave new world and one with a steep learning curve, but ultimately the benefits make the initial effort worthwhile. However, with this book to help you through your journey, you should find that a lot of pain will be taken out of this learning curve, guiding you in the right direction while you build your first business application in Silverlight.
Who This Book Is For
This book covers not just Silverlight as a technology, but also the important concepts in designing and developing business applications. From structuring your application to actually implementing features, it covers most of the lifespan of developing a business application in Silverlight.
To follow along with this book, you should know your way around Visual Studio well, have a reasonable degree of familiarity with C# and its features (such as generics and LINQ, although experience with a similar language such as Visual Basic or Java may suffice), be comfortable with designing and querying databases, and have a good understanding of object-oriented design (OOD). Some prior business application development experience (or understanding of what building a business application entails) is an advantage, but isn’t absolutely necessary, as I will discuss the reasoning behind many of the concepts unique to business application development as needed. However, you may need to refer to alternative sources for more information when the concepts are particularly complex and detailed. For example, a good understanding of design patterns (such as those described in the influential book Design Patterns, by the authors typically referred to as the Gang of Four [Addison- Wesley, 1994]) is important when designing business applications, but complete coverage of these in the context of designing Silverlight applications is really a whole book in its own right. CHAPTER 1 INTRODUCTION
About This Book
This is not a book simply about Silverlight as a technology, and it isn’t about covering Silverlight from end to end. Silverlight features such as streaming video, Deep Zoom, animations, sounds, and others that are not generally a core requirement in business applications will not be covered. This is a book specifically targeting the needs of designing and developing business applications, and how to do so when using Silverlight as a development platform. That said, you may be well versed in the process of business application design and merely be interested in how to apply your knowledge to developing business applications in Silverlight—this book caters to you too. You may even pick up a few things as you go!
You may have noticed that many books, web articles, and presentations take a rather simplistic view when discussing building business applications in Silverlight, and these techniques rarely hold up to scrutiny in real-world projects. Instead of just giving you all the pieces and leaving you to fit them together yourself, this book is designed to act as your guide when creating your own business application, leading you through the difficult problems you will encounter and providing one or more solutions for each problem. Business applications involve more than simply retrieving some data and displaying it on the screen—this book will allow you to peer into all the nooks and crevices that represent good business and application design practices.
This book is designed to be read from start to end rather than simply being a reference guide. Concepts will be introduced gradually to save overwhelming you with too much information at one time. This means that when some concepts are introduced, we will take shortcuts in other areas in order to focus your attention on the concept being taught, and move on to more robust implementations in subsequent chapters. Therefore, some of the Silverlight-specific lessons in early chapters are not designed to be put into immediate use, as they won’t necessarily reflect all the recommended development practices in real-world projects, but are provided merely as a means of easing you into the world of Silverlight development.
Note For example, the Model-View-ViewModel (MVVM) design pattern commonly used in Silverlight/WPF business application development is not covered until the later parts of the book. You will probably want to use this pattern in your applications, but the earlier chapters forgo this pattern in their examples as it introduces a lot of complexity that will potentially confuse you when attempting to focus on and convey other important concepts. Despite its position in the later parts of the book, incorporating this design pattern into your project should not be an afterthought. Therefore, this book should not be considered a step-by-step guide, but an all-encompassing guide to all the concepts important to building business applications in Silverlight.
By the completion of this book you will have learned most of the techniques for designing robust business applications and how to implement these techniques with a Silverlight-based project. While it would be impossible to cover each and every concept that could be employed when designing and developing business applications, this book will cover those that are the most important for developing a well-structured business application.
Unfortunately, it simply isn’t possible to explore the complete myriad of scenarios that you may encounter in your application requirements, nor is it possible to cover every possible solution to a problem. The primary decision that needed to be made when writing this book was to decide on a single means for communicating between the server and the client. Due to the wide array of means for a
CHAPTER 1 INTRODUCTION
Silverlight application to communicate with a server, it would be simply impossible to cover them all and do them justice. For this reason I chose to cover one technology in depth. For most end-to-end business applications in Silverlight (which is the primary focus of this book), RIA Services is your best option for handling communication between the Silverlight client and the server, and therefore this book will focus on using that technology as the framework for this task.
Note If you decide RIA Services is not suitable for your needs, don’t despair—the functionality covered in this book is not solely dependent on RIA Services, and there should still be large amounts of information useful to your project.
Note that you don’t need to use every concept taught in this book in your own applications, as at times some of the concepts may be excessive (depending on the size and type of project you are working on) or inappropriate. These concepts will be noted with the scenarios that they are most suitable for, in order to help you make an informed choice.
About the Author
My name is Chris Anderson and I will be guiding you on your journey building business applications in Silverlight. Throughout my career as a developer I’ve designed and built many business applications across multiple platforms and a number of industries, including construction, finance, sales, logistics, and field services, to name just a few. However, despite all my development experience, I still faced a steep learning curve when I first came face to face with Silverlight. Back then, Silverlight was still in its infancy, but I could see its future potential as a platform for applications of all types—especially in the area of business application development. It had a small runtime, could be easily deployed, had a lot of exciting potential for rich user experiences, and best yet, had the power of the .NET Framework behind it (albeit a subset, but a substantial subset).
While it wasn’t a vision shared by many people at the time, there was quite an interest in the topic when I started writing about it. I published a series of articles on the topic on SilverlightShow
(for Silverlight 2 beta 2, and then Silverlight 2 RTW), but it was still somewhat
( hard going, with a lot of hurdles to jump and issues to work around. However, it was obviously a market that Microsoft saw potential in too, and with the beta release of Silverlight 3 there was suddenly a big focus on support for developing business applications (making much of my previous work redundant in the process). The vision had suddenly become reality.
Developing business applications in Silverlight has become substantially easier since those days, but you will still face a steep learning curve that will make getting up to speed a little slower than you might like (primarily in order to effectively use XAML to design your user interface). I’ve specifically structured and written this book to help you through that learning curve, guide you in the right direction, and solve the problems you are likely to encounter, so you can be working and productive in minimal time.
I welcome any and all feedback (preferably constructive), and you can contact me via my blog at on Twitter at @ChrisTheCoder. CHAPTER 1 INTRODUCTION
Silverlight Overview
Microsoft has a number of different platforms for building applications, with Silverlight being the newest addition to the family. Let’s take a look at what Silverlight is and how it fits into the big picture of software development platforms.
What Is Silverlight?
It’s important at this stage to establish exactly what Silverlight is and what it isn’t. Silverlight is an RIA platform. RIAs could be considered a cross between desktop applications and web applications. They run within the user’s web browser (with some exceptions), and use a browser plug-in to run the application within a sandboxed environment. RIAs are not a new concept, although not all have been a success for various reasons. Adobe Flash is a notable exception, having achieved huge popularity over the last decade, as well as a market penetration of 99 percent of Internet-enabled personal computers in mature markets and 98 percent in the enterprise (according to Adobe’s own statistics available here:
You will find a number of parallels between Silverlight and Adobe Flash. Both run as browser plug- ins, providing a platform for self-contained applications running on the client (as opposed to being dependent on a server controlling the application). Of course, there are numerous differences between the two technologies, but if you take a look at the space in which Silverlight is competing, Adobe Flash (combined with Adobe Flex) is without doubt Silverlight’s biggest competitor.
Market Penetration/Reach
Although Adobe Flash has an almost ubiquitous market penetration, Silverlight is rapidly catching up. Scott Guthrie (corporate vice president, .NET Developer Platform) announced at PDC (in November 2009) that the market penetration was at 45 percent of all Internet-connected devices in the world (note that this is a broader measure than that of Adobe’s), and at the launch of Silverlight 4 in April 2010 he announced that it was now approaching 60 percent. For in-house business applications, the issue of Silverlight’s market penetration is of little concern, as the Silverlight runtime can be incorporated into the organization’s standard operating environment (SOE) and deployed automatically to all the machines throughout the organization. However, for public-facing applications, you should be aware that not all client machines will have the Silverlight runtime installed. Deploying both the Silverlight runtime and your application effectively to users is detailed in Chapter 15.
Note Another good source of statistics comparing the two plat
Focus
Silverlight’s initial focus was toward media applications (directly targeting Adobe Flash’s biggest market)—particularly in the area of video, vector graphics, and animations. However, it has more recently been focusing heavily on business applications, and is arguably the most powerful of the competing RIA platforms in this respect. With advanced support for data binding, a rich set of standard
CHAPTER 1 INTRODUCTION
and supporting controls, and the RIA Services framework, it has also become a viable platform for many business applications.
Compatibility
The Silverlight browser plug-in works with all major browsers and across the two most popular operating systems—Microsoft Windows and Apple Macintosh (Intel x86–based machines only). The Moonlight project (by the team from Novell working on Mono, a cross-platform open source implementation of the .NET Framework) can be used to run Silverlight applications on Linux, but unfortunately its releases lag behind the Microsoft releases.
At the time of writing, there is currently no support for mobile operating systems such as Windows Mobile (which is superseded by the Windows Phone 7 mobile operating system), Apple’s iPhone, Symbian (for Nokia devices), BlackBerry, or Google’s Android, although there are future plans to provide support for some of these devices.
Windows Phone 7
The Windows Phone 7 operating system has a Silverlight-based user interface, meaning that most applications for it will be written in Silverlight. Applications need to be written specifically to run under this operating system, as it won’t run standard Silverlight applications (i.e., you won’t be able to browse to an application in the web browser and run it). Applications written for the phone are essentially Silverlight 3 based; however, this should be enough to enable you to port much of the same code you write for your business applications targeting Silverlight 4 to a Windows Phone 7 version at some point in the future. This will open up many exciting new possibilities for sharing a large portion of your code base (and development knowledge) between both your standard and mobile applications.
The Silverlight Runtime
The Silverlight runtime is a 6MB download (small by today’s standards) including a subset of the .NET Framework and a full implementation of the Common Language Runtime (CLR) engine. This has the huge advantage of enabling you to write code in any .NET language, including (but not limited to) C# and Visual Basic—meaning that you can develop applications in exactly the same language that you are used to working with. Application code is compiled into assemblies, which (along with XAML files and other resources) are combined into a XAP file. This file can then be downloaded to the client and executed within the plug-in. Silverlight applications run within the browser are sandboxed (having extremely limited access to the host machine), meaning that Silverlight applications are inherently safe to be run and cannot cause any damage to the user’s computer (by design).
Note Silverlight applications cannot make use of assemblies that target the full .NET Framework, but assemblies targeting Silverlight can be used in applications that target the full .NET Framework. CHAPTER 1 INTRODUCTION
Out-of-Browser (OOB) Experiences
While Silverlight applications are generally run from within a browser, from version 3 of Silverlight onward they can be run outside of the browser as if they were standard Windows or Macintosh applications. An icon can be placed on the desktop and/or the Start menu to open the application, and the application can automatically update itself when a new version is available on the server. The original implementation of OOB used the same sandboxing model as running the application in the browser, but in version 4 of Silverlight a new feature was added to allow the application to be installed with elevated trust permissions. This enables the application additional access to the host machine, and opens up a new range of possibilities to your Silverlight applications (when the application is being run in OOB mode). With trusted applications in Silverlight 4, you also have access to the Component Object Model (COM), which being a Windows-only feature breaks the truly cross-platform nature of the platform, but enables you to access many Windows features and integrate more tightly with other applications and the operating system.
In the .NET world, Silverlight’s closest relative would be Windows Presentation Framework (WPF). Both use Extensible Application Markup Language (XAML) to define their user interfaces, and Silverlight essentially started as a web-deployed subset of WPF. If you are familiar with WPF, you will be able to write Silverlight applications reasonably easily (and vice versa), despite there being a number of features in each that are not available in the other (although they are becoming more aligned with each release of each).
A Short History of Silverlight
Silverlight has matured rapidly in its short three-year lifespan. Let’s take a look at how it has grown in that time.
Before there was Silverlight, there was WPF. Introduced with version 3 of the .NET Framework, it targeted the rich client market, pioneered the use of XAML to define user interfaces, and demonstrated the new possibilities that XAML could enable. WPF applications could be deployed via a web browser (as an XBAP), but they required the full .NET Framework to be installed, and could only be run under Windows.
Silverlight 1: September 2007
Microsoft then started working on a project called WPF Everywhere (WPF/E), which was essentially designed to be a web-deployed subset of WPF that had its own runtime and ran within a browser plug- in. It used XAML to define the user interface and required you to write code in JavaScript. It had little in the way of controls, and was predominantly focused on media-type applications (video, animations, and vector graphics). This became Silverlight 1.
Silverlight 2: October 2008