[Edit 2/5/12: fixed spelling of 'ignorable' everywhere].
Or “What is this weird XAML I get from workflow designer that doesn’t look like ‘normal’ XAML?”
(No ‘news’ today, just some WF4 olds in article format, and mostly implementation level trivia stuff at that, but I hope it’s interesting. )
Here’s something I whipped up today while trying to do some XAML related testing. One problem with XAML generated by WorkflowDesigner.Save() is that it’s actually very special XAML, and different from what you would get from just calling good old ‘XamlServices.Save()’. But have you ever looked at all the differences and wondered what they are? Well, let’s take a look! Here is some actual XAML generated by the actual Visual Studio 2010 workflow designer.
Wow, so much weird-looking XML.
Interesting looking thing #1. x:Class. What is that? If you know what the runtime type of the basic object you’re usually working with in ActivityDesigner is, it’s ActivityBuilder. So why is the root element <Activity x:Class> and not ActivityBuilder? Well, Matt Winkler discussed this one a long time ago, so I’m not going into that deeply, but it’s probably interesting to know that it’s because it was written using a special XamlWriter, one from ActivityXamlServices.CreateBuilderWriter().
Interesting looking thing #2. sap:VirtualizedContainerService.HintSize=”240,240”. What is that? Actually it’s not that weird. This is a XAML AttachedProperty. Through regular XAML rules, we can figure out that it’s referring to the VirtualizedContainerService.HintSize property. This will actually be written out by a regular XamlXmlWriter, or XamlServices.Save(), if you have already set the attached property on an object (in this case it’s set on the ActivityBuilder while WorkflowDesigner is runing).
Interesting looking thing #3. mva:VisualBasic.Settings=”Assembly references and imported namespaces for internal implementation". This is also a XAML AttachedProperty. In this case it’s indicating something kind of special. But hang on one second!
Interesting looking thing #4. There are so many unused XAML namespaces. Why?? Specifically, nearly ALL of the xmlns:blahblah=”clr-namespace:blahblahblah” namespaces in your documents are never referened by XML elements or attributes. Why? Well it’s because of the mva:VisualBasic.Settings. What mva:VisualBasic.Settings is indicating is that all of your xmlns namespaces are going to be treated as imported namespaces in your workflow’s VB expressions. What’s an imported namespace? It’s a namespace which will be searched by the hosted Visual Basic compiler, i.e. it’s like a C# using statement. So basically XAML has all your workflow’s ‘using’ statements hidden as xmlns namespaces. This actually creates an annoying bug or two in the workflow designer experience. You can’t, for instance, add a variable of type X to your workflow without adding the namespace of that type to your namespace imports. But adding namespaces occasionally has an unwanted effect of creating namespace resolution ambiguities! So you end up having to use a fully qualified namespace in your Visual Basic expression to resolve that. Which is just like not having imported the namespace you wanted to import in the first place! (Meh) Anyway, since it’s just another attached property, again to set this one again all you need to do is set the attached property on the object before you serialize.
Interesting looking thing #5. Looking at xmlns:x=”http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation” we realize not every xmlns namespace is a clr-namespace in XAML. Even though, in this case, it really does often refer, in its XAMLy-way (like in the HintSize attached property) to CLR types! Actually you can define your own XAML Http namespaces as well, if you want to. It’s harder to describe just when it is a good idea to do this (define an http namespace to use), in fact I don’t claim to understand that fully yet.
Interesting looking thing #6. mc:Ignorable attribute. I purposely left this one to last! What does it mean? Well, if you research a little on your favorite search engine, you’ll find that mc:Ignorable is not a XAML-ism, it’s actually an XML-ism/XAML-ism for ‘markup compatibility’. What’s markup compatibility? It’s a way of saying ‘you can ignore this stuff if you don’t understand it.’
Anyway the real subject which prompted me to write this blog is the question how do I add mc:Ignorable to a XAML file.
As far as I know there isn’t actually a XAML-based way of adding this attribute. So I had to do it through XML… and on the way I added a couple attached properties and stuff for fun, so you can see how to do some of this stuff manually - just in case the need should ever arise!