Intellisense in XAML for your types too!
(This shows an XML editor view showing elements from a clr-namespace mixed in with element from xaml/presentation.)
I’ve spent some time the past few days trying to complete building a solution to enable this.
History of the XSD Generator
The ASP.NET team had to do similar things…generate an XSD using reflection against .Net assemblies. Several years ago, probably 2002 or early 2003, I got a drop of their code. I had a pm intern build a tool that would reflect on PresentationFramework, PresentationCore and WindowsBase and generate an XSD for "Avalon’s" types.
Over the years, I ended up enhancing this tool to improve the intellisense experience for XAML inside of XSD aware tools. This included a major push during August of 2005 to make the XSD relect most of what was possible. (I no longer enforced that only a Page or Window could be at the root, for example, any object would be fine.) During that push, I ended up adding the concept of SubstitutionGroups to the XamlPresentation2006.xsd.
Substitution Groups enable you to model subclassing like model in schema. It gave me hope that I could support non-"xaml/presentation" types in XSD appropriately – something I had long though impossile with XSD.
Now I have been working on adapting the xsd generator to work on different .dlls.
For example, in my WpfUtilities dll that I am working on, I define a ProxyElement (which I’ll write about in the future). If a new XSD is created that defines this element:
<xs:element name="ProxyElement" type="dProxyElement" substitutionGroup="wpf:sgDecorator"/>
And if we put that XSD in c:\program files\microsoft visual studio 8\xml\schemas with the right clr-namespace uri, intellisense works.
What is left
Unfortunately, I had to hand modify the output of the schema generation tool to make it work. I still need to:
- adapt the XSD Generator to do all those things the right way
- consider how to fix a problem I noticed in XamlPresentation2006.xsd (i didn’t create substitution groups for elements which don’t have subclasses.)
- figure out where/how to ship this tool (and potential changes necessary for XamlPresentation2006.xsd) – i want to get it out soon…
As I’ve probably written about a few times, the Visual Studio team is planning on building a native XAML Editor…one that doesn’t use XSD, but instead just directly examines types in assemblies, etc…
So, hopefully we can count the number of months that this will be useful on 1 (or maybe 2 hands)…