XAML Syntax Tightening: Order Matters


In recently porting some code to Beta 2 of WPF, I hit one of the XAML Syntax Tightening changes that Tim referred to in his post on Breaking Changes in Beta 2. Basically, order matters as far as referencing resources.  If you try to reference a resource in XAML, like a style or control template, before it has been declared, you will get an error at runtime. For example, you can’t do this


<Style x:Key=”myStyle” BasedOn=”myBaseStyle”/>
<Style x:Key=”myBaseStyle” />


Fortunately, the fix is easy.  In the case above, just make sure myBaseStyle comes before myStyle.  Of course if you have 200 different resources all that are interdependent and were added adhoc in a speedy dev cycle, it can take awhile.

Comments (3)

  1. Konstantin says:

    That’s certainly good for code styling and readability, but it reminds me of functional programming model and bad designed OOP.. 🙁

  2. karstenj says:

    I must say I agree with you to a certain extent.  Your reaction was my initial reaction as I ported the code.  Rob Relyea (http://www.longhornblogs.com/rrelyea/default.aspx) might have better insight than I as to why the change was made.

  3. andrew whiddett says:

    No … i have to refactor about 20,000 lines of XAML now !!! Heck.