Silverlight 4 in Action by Pete Brown is a comprehensive guide to Silverlight application building using C#. It features several practical examples that explore flexible layout, control extensibility, the communication and binding models, rich media, animation and much more.
This book explores pragmatic questions in patterns, testing, and performance optimization. No previous experience with Silverlight is required.
The main focus of the book is:
- Core XAML
- Browser and the desktop integration
- Rendering, layout,transforming and panels
- Human input, text and controls
- Binding and data controls
- Input validation
- Networking and communications
- Navigation and dialogs
- Structuring and testing with the MVVM/ViewModel pattern
- WCF RIA Services
- Graphics and effects
- Printing
- Displaying and capturing media
- Bitmap images, animation and behaviors
- Resources, styles, and control templates
InfoQ had a Q&A with the author Pete Brown, who is the Microsoft Community Program Manager for Silverlight and WPF: InfoQ: Hi Pete, would you like to tell us a little bit about yourself and how you came about writing a book about Silverlight? Pete: My programming background starts in the 80s with the Commodore 64, something I still hold dear in my heart. From there I moved on to writing DOS applications (TSRs and fun stuff) for fun. Since the early 90s, I’ve been professionally programming for Windows using tools starting with Borland C++, Delphi 1.0 and Visual Basic 3.0. When Silverlight first came out (managed code) I was really excited. A two team person (me and another developer) created the first Silverlight managed code application ever to go into production. I was hooked on the technology from that point forward, eventually becoming a WPF and Silverlight MVP. These days, I lead the Developer Guidance (PnP) Community team at Microsoft. I have some really great guys working for me, concentrating on Windows Phone 7, Silverlight, HTML 5, ASP.NET, jQuery, and more. I personally concentrate on Silverlight out-of-browser, WPF, XNA and other “on the client” technologies. We create content for MSDN and the asp.net, Silverlight.net, and other web sites, plus sample applications and blog posts. We also speak at a lot of conferences and generally hang out on Twitter all day. It’s an awesome job. A while back, I was contacted by the authors of the first edition of the book and asked if I could add a few things and take it over to be the second edition. Those “few things” ended up being about 600 pages of new content J This was my first book. I endeavored to “do right” by the community I’m both in and serve. I wanted to make sure we had the best and most complete Silverlight primer and reference possible. Time will tell if the book lives up to that, but I think it will. InfoQ: What is Silverlight and what is the problem that it tries to solve? Pete: Silverlight is a .NET-based application development platform. The first two versions (Silverlight 1 and 2) targeted primarily web graphics and media applications. The subsequent versions made significant improvements in areas important to building robust business applications, while continuing to up the ante for awesome web and media applications. Silverlight is cross-browser and cross-platform. It expands the reach of your .NET development skills so you can build applications that run on the Mac, and on Windows in a number of different browsers. Linux support is also available through the open source (and Microsoft-encouraged) Moonlight project. InfoQ: What are the features in the latest version of Silverlight that you think are most valuable for developers? Pete: I think they’re all valuable for different developers J. If you’re a data-oriented application developer, you’ll appreciate the release of WCF RIA Services, as well as enhancements to binding and validation. If you’re a media developer, you’ll like the improvements to the media stack and optional DRM stacks. If you’re into games and interesting visualizations, you’ll appreciate the WriteableBitmap class. There’s a little there for everyone. InfoQ: How do you see customers using Silverlight? What are the most typical use cases where Silverlight shines? Pete: Prior to joining Microsoft, I saw business customers taking a serious look at Silverlight; as far as I know, that trend is continuing. Applications that don’t require heavy system integration are doing well as Silverlight applications. You get a desktop application programming model with a web deployment model, but without the hassle of traditional web applications. That’s hard to beat! The company I worked for had a number of Silverlight business application projects lined up with various customers. InfoQ: Is it easy for developers to create their own custom controls? Are there open source components out there and how is the market for Silverlight components suites? Pete: One interesting aspect of Silverlight (and WPF) development is that you often don’t need to create your own custom controls. Let’s say, for example, you want a display of contact cards that allows selection of one of them. In many other platforms, you’d need to go hunting for a third-party control. In Silverlight, you can easily restyle a ListBox control so the items are in a WrapPanel and are represented with a picture and some paragraphs of text or fields. Styling, templating, binding – all key things here. That said, sometimes you do need to create your own control. It’s really easy to do this in Silverlight: you create a class that holds the implementation and a Xaml file that holds the default template. The code contract between them is handled by “Parts”. I cover all this, as well as the simpler UserControl model, in Silverlight 4 in Action. InfoQ: Are there things in Silverlight that you don’t like? What new features would you like to see being implemented in the next version? Pete: As I’m aware of our product plans for future releases, I can’t really answer this :) InfoQ: What do you suggest in terms of tooling? Is Visual Studio enough or are there other tools that you think are valuable for developers. Pete: For many developers, Visual Studio 2010 will be sufficient. The design surface was really improved for both WPF and (of course) Silverlight in this version. If you want to start creating custom controls with specialized UI, or want to style existing controls, or manipulate content from your design staff, you’ll definitely want to pick up Expression Blend. InfoQ: In your book you suggest that for any application that goes beyond the basics, it is valuable to use the Model-View-ViewModel (MVVM) pattern. Would you like to elaborate a little on that? Pete: When you first learn a new technology, it’s often hard to intuit the best practices. Patterns like MVVM help provide a structure to the application that almost force you to do things “the right way”. For example MVVM is very heavily binding-centric. If you try and do binding without an object that acts like a ViewModel, you’ll quickly tie yourself up with references that point all over the place. The approach I took in Silverlight 4 in Action was to start with a typical Code Behind approach, then refactor that into a decent MVVM pattern application over the course of several steps. I explained what each change buys you and what you gain by making it, or lose by leaving it out. I think this is a more digestible approach to MVVM than the firehose method I’ve seen elsewhere. It also allows the developer to make decisions based on their own capabilities and needs rather than worrying that they aren’t MVVM-enough. InfoQ: What would be your advice for teams that are just now starting their first Silverlight project. What are the main pitfalls they should be careful about? Any “best practices”? Pete: Embrace binding! I have a “Then things Every Silverlight and WPF Developer Needs to Know” presentation that I give at conferences and code camps. Binding is one of the most important of the items in that list. If you find yourself writing code to assign values to UI controls, you’re probably making life much more difficult for yourself. I don’t want to say “you’re doing it wrong”, but you know that’s what I’m thinking J The other thing is to let the layout system work for you. Some people fight the layout system, trying to force controls into unnatural positions in the screen. Once you understand the layout system and how it works, you’ll be able to do anything you want, without hardcoding widths and heights of controls at various levels in your tree. InfoQ: With the emergence of HTML5 and the browsers becoming more capable of facilitating Rich Internet Application without plugins, what do you think is the future for Silverlight? Pete: Both Silverlight and HTML5 have a role to play in the future of application development. I think we said it best here: http://team.silverlight.net/announcement/the-future-of-silverlight/ . This is all still shaking out, and predicting the outcome is hard. I like HTML for some things, Silverlight for others, and WPF for still others. Even if one of those technologies were to “win”, it would still be so far out as to not impact applications people need to develop today or in the near future. However, rarely does any one model obviate the need for others. What usually happens is the technologies become more focused and more specialized, or the applications you write end up being kicked up a notch due to the increased capabilities of the combination of platforms. InfoQ: What do you think would be the most valuable take away from your book for people that have just found about Silverlight and what for seasoned users of this frameworks that want to take it to the next level? Pete: The ability to use your .NET skills to create new types of applications, freed from the rigid layout systems we’ve had in the past, is a huge take-away. I’d also like people to read the book and be inspired to create applications for themselves and for their businesses. Oh, and that I love Star Blazers and I’m a bit of a geek ;) You can find more information on Silverlight, WPF and Rich Internet Applications, right here on InfoQ!