Silverlight for Developers (Part I)
Join the DZone community and get the full member experience.Join For Free
I recently gave a talk for the Corvallis .NET User’s Group (CDNUG) about using Silverlight as a developer. Silverlight is pitched as a Flash-replacer, a video streaming enabler, and a designer’s dream, but it doesn’t get much love for business applications or more general use. This isn’t actually fair, as Silverlight has amazing databinding and custom presentation features just like it’s older brother WPF.
The first challenge to developers with Silverlight is the tooling. We devs are used to our environment being a certain way. Visual Studio, SQL Server Management Studio, and other similar applications use an MDI layout that makes sense to us. Expression Blend (the tool of choice for Silverlight/WPF design) is almost totally alien!
Comparison of Blend and Visual Studio
It’s not just the dominant darkness of the theme either! The control toolbox, properties, resources, and other features are just not intuitive to someone with several years of Visual Studio experience.
I Do Declare!
Another big difference to understand isn’t unique to Silverlight, but rather is an attribute of XAML-based declarative programming in Silverlight and WPF. While all UI elements are based on classes, just like in Windows Form applications, the declarative model opens up a whole different way to modify controls. You can set properties of a control, and you can sub-class a control, but the preferred method is to use styles and templates.
Styles are an interesting way of setting properties of objects independent of the objects themselves. You could think of it as a collection of property names and values, and then applying that collection to an object using reflection. It’s more slick than that of course though! Once a template is created, you can apply it to any instance of a given type of control, similar to theming.
Templates refer to the actual composition of a control. From Windows Form programming, we think of a TextBox as a root-level element. In XAML though, everything is a composite control. A TextBox is a collection of rectangles and a content presenter. Some elements are shown or hidden based on focus, disabling, or other states. Modifying the template means declaratively adding or removing elements. This could be to add a magnifying glass to a search text box or to change a button from rectangular to circular.
Default Silverlight Button template
To Be Continued…
In my next post, I’ll talk about data binding in Silverlight…
Published at DZone with permission of Arian Kulp. See the original article here.
Opinions expressed by DZone contributors are their own.