Featured Posts

WPF and the Event Routing Paradigm, with Bacon Since the first event-driven language came down from the mountain and became part of the software development vernacular, there has been a certain notion of how an event works. Subscribe...

Read more

How to stop Expression Blend 4 RC from crashing on... So you’ve downloaded Expression Blend 4 RC but when you start it up, Blend crashes hard.  It’s never done that before, right? What do you do?  Well, you can...

Read more

The WPF Must-Grok List Robert A. Heinlein defined the word grok as: Grok means to understand so thoroughly that the observer becomes a part of the observed—to merge, blend, intermarry, lose identity...

Read more

Yes, Virginia, TextBlock.Text Will Support MultiBinding One of the features introduced to WPF in version 3.5 SP1 is the StringFormat property. If you’re unaware, StringFormat allows you to bring the String.Format capability...

Read more

Why Are WPF Developers Trying to Kill Menus? Somewhere along the line, and I’m not motivated enough to research it, menus apparently became bad.  I don’t mean they ever stopped working or became unsuitable for the...

Read more

using System.Windows; Rss

Silverlight Proof-of-my-Concept Update

Posted on : 11-12-2009 | By : Christopher Estep | In : Silverlight

Tags: , , ,

0

I’ve been busy on my Silverlight test control and it’s been more fun than I’d expected and it’s actually been a lot easier than I’d expected, too.  So what I’ve been doing is delving into some of the more internal differences to extend what I’d originally planned further.

From a layout perspective, Silverlight 3 is very similar to what I would do in WPF, but it’s much more basic.  You can do many of the same things, but with Sl, it’s pretty scaled down.  By this I mean that WPF is a richer framework and handles some of the details that you otherwise have to do manually in Silverlight.

One thing I’ve noticed is that Silverlight is very lean with its overloaded constructors.  I’m not complaining, it’s an observation.  I’ll give a real example.

In WPF, I could make a rotate transformation like this:

  child.RenderTransform = new RotateTransform((angle * 180 / Math.PI));

The problem  with doing that in Silverlight is that RotateTransform only has the default constructor.  Fortunately, C# 3 included Object Initializers, so the alternate syntax I have to use is completely painless:

  child.RenderTransform = new RotateTransform()
       { Angle = (angle * 180 / Math.PI) };

How awesome is that?

So you still have the benefit of a lighter footprint without the overloaded constructors (which are just get/set anyway in this case), but still painlessly instantiate and initialize the object.

There needs to be a word of caution to newer programmers.  Don’t assume that you can universally bypass all overloaded constructers using Object Initialization as I’ve done above.  While a significant number of such constructors are nothing more than get/set convenience mechanisms, this is not the case every time.

Object Initialization is easier to read than a parameterized, overloaded constructor.  Just don’t forget that constructors can (and often) do more than just initialize properties.

Know your code!

Popularity: 7%

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DotNetKicks
  • StumbleUpon
  • LinkedIn
  • Facebook
  • TwitThis
  • Digg
  • DZone
  • Reddit
  • Technorati
  • email
  • Print

Comments are closed.