Regard The Sequence of XAML Style Definition

Going through a Windows Store App XAML sample, I came to the point where a pre-defined style, located in Common/StandardStyles.xaml file, should be used. The tutorial at told me to remove the comments of PicturesAppBarButtonStyle.

Well, that was not that hard. I deleted the XML comment markup and moved the style somewhere at the top of the file. Then I added a button to a page and started the app.

It crashed! The exception handler told me that there was a XAML parsing error. So the first thing I changed was to remove the newly added button. But I still ran into the same exception. I came up to the uncommented style. Just put it into comments, everything worked fine again. Why that? Was the generated code erroneous?

No – it was my fault 🙁 I put the new style above the declaration of its base style. Just moving the it behind the base style definition, the app works properly.

After creating a small Silverlight test app I can tell that it’s not a Windows Store App issue. It is a XAML parsing thing. I never had this problem before, even though I built some Silverlight apps. It seems that I had luck, because I automatically put the derived styles behind the base styles in my code.