So I start to do some coding in XAML (Avalon) by beginning with the basics of how XAML works when I hit this in the SDK. In a section called Adding Code under the XAML Overview the following is written:
If you do not want to create a separate code-behind file, you can put your code inside the “XAML” file. is an element defined in “XAML” that can contain inline programming code that supports the “XAML”. The following example illustrates inline C# code. Notice that the code is inside a tag and that the code must be surrounded by so the markup parser will not try to interpret the code.
with the following code snippet:
void Clicked(object sender, RoutedEventArgs e)
{
button1.Content = “Hello World”;
}
]]>
and then some more text:
There are a number of reasons however for discouraging use of this facility to place code inline. In terms of architecture and coding philosophy, separating markup and code-behind enables designer and developer roles to be much more distinct and defined, and putting them both back into the same physical file again conflicts with this principle. On a technical level, the code that you put inline can also be difficult to write because you are always writing into the “XAML” page’s default partial class, and using its default scoping. You may need to fully qualify many of your application programming interface (API) calls you make here because you cannot add ‘using’ statements. And you also therefore can’t define multiple classes in the inline code, everything you add inline must exist as a member or variable within this default class.
I don’t know about you but haven’t we seen enough of this.When all of our architecture books and articles press the point to separate your code why in the world would this still be possible. Sure I know XAML is based on XML and XML does have CDATA but couldn’t we have done something here to discourage even the capability of doing this. I really hope that this does not make it into the release version and no the disclaimer at the end of “discouraging use of this facility” doesn’t cut it.