Friday, August 9, 2013

XAML as a mystical experience, Pain Level transcendent

As I’ve blundered through learning XAML in Silverlight 3, 4, 5, WPF, WP7, and now WP8 and Win8, it has always been a painful experience.  I recall the very first time I saw XAML and thought “Oh, no – I’m going to be staring at the ugliness of XML angle brackets for the rest of my life”.  But the promise of portable UI components and a nice designer in Blend made me persevere.  Until now.

Sure, one can eventually achieve guru status and understand all the various binding quirks of XAML and be wonderfully productive.  But for average programmers like me, the pain has always been excessive.  Keeping track of which XAML features are available on each platform is a headache.  Writing pages of XAML to do something simple like changing the background color of a control is a test of one’s faith.  From:  http://www.zagstudio.com/blog/1314#

    If we attempt to use the styles and templates from our earlier WPF example, we quickly discover that WPF XAML is incompatible with Win8 XAML in a few places (mostly the same places as Silverlight):

    • DataTemplate doesn’t have a DataType property. Instead, we have to refer to DataTemplates explicitly by x:Key.
    • ControlTemplate doesn’t have a Triggers collection. Instead, we have to use VisualStateManager to control the appearance of selected and unselected items through visual states.
    • Canvas doesn’t support the Canvas.Bottom or Canvas.Right attached properties. Instead, we must use Canvas.Left and Canvas.Top to position child elements.
    • Various other properties have been moved, simplified, or eliminated.

So, my new resolve is to do as much as possible in code.  Fill up my code behind files.  Write more foreach loops.  At least I can see what’s going on instead of relying on XAML magic to do the right thing.  Hopefully multiple platform support will actually be simpler.