Rob Relyea


August 2005 - Posts

  • XAML Editing in an Xml Editor - major schema enhancement coming with PDC release

    I've written a few times in the past about how we provide a WPF ("Avalon") + XAML schema in the Visual Studio 2005 Extensions for WinFX.

    A major schema quality update is in the works for our PDC release of the VS Extensions.

    Avalon + XAML Schema Files
    XML Editor (like the one in Visual Studio) can use XSD schema files to provide Intellisense support for many XML formats. If you are editing with VS' XML Editor and want a better experience, you can put an .xsd file in \program files\microsoft visual studio 8\xml\schemas\

    Determining Content Model for An Object

    The XAML parser design in the past has made it hard for tools or people to understand what the content model for an element is.  In the upcoming PDC build, we've added a new Attribute that allows any object to define which property is their "content" property.  Panels, for example, put their children in their Children property.  Knowing that gives a critical missing clue to solve the "what is the content model" question.

    Because the Children property is of type UIElementCollection, you know that any set of UIElements can be put inside a Panel.

       <Button />
       <ListBox />

    Determining Set of Types in a Xmlns Uri

    We also have an attribute (XmlnsDefinitionAttribute) that allows a class library author to define what a xmlns uri means to XAML.  It helps create a mapping from an xmlns uri to a set of clr namespaces in specific assemblies.

    AssemblyInfo.cs for PresentationFramework.dll
    [assembly: XmlnsDefinition("", "System.Windows")]
    [assembly: XmlnsDefinition("", "System.Windows.Controls")]
    [assembly: XmlnsDefinition("", "System.Windows.Documents")]
    [assembly: XmlnsDefinition("", "System.Windows.Shapes")]
    [assembly: XmlnsDefinition("", "System.Windows.Media")]

    Enhancments to Avalon2005.xsd

    Using the information about content model and XmlnsDefinition, we've changed the schema generation tool that creates Avalon2005.xsd.  That tool no longer relies on a difficult to keep up-to-date data file that describes the content model of all elements.

    • use XmlnsDefinitionAttribute to discover the appropriate types to include in schema
    • filter inappropriate types that can't be represented in XAML (no default constructor, etc...)
    • allow any "object element" to be the root (I no longer suggest Page, Window, etc... as the only valid roots)
    • drastically improve the content model exposed for each element
      • allow all property elements (<ClassName.Property>) as children (I no longer suggest the 2-3 useful ones) -- note, Grid.Children is one of the property elements allowed by the schema...the xaml parser will support it, but
      • support the property content model for children (no longer based on a partially correct data file)
    • properly expose all possible attached properties for an element in the schema (based on the type in the SetFoo, GetFoo static methods)
    • improve attribute value enum values (discover the possible values for Brush by looking at Brushes, etc...)
    • merge in intellisense information about each object, property and element from PresentationFramework.xml, PresentationCore.xml, etc... - providing inline descriptions as you edit in the xml editor.

    Editing Schema vs. Validating Schema

    Schemas can either be focused on assisting editing or can be provided to be completely definitive for validation.  Avalon2005.xsd is focused on being an editing aid for XAML.  Over time, we'll probably start releasing 2 editing and one validating.

    Editing Schema for System.Windows.Data.BindingMode enum:

    <xs:simpleType name="frlrfSystemWindowsDataBindingModeClassTopic">
    xs:restriction base="xs:string">
    xs:enumeration value="TwoWay"/>
    xs:enumeration value="OneWay"/>
    xs:enumeration value="OneTime"/>
    xs:enumeration value="Default"/>
    xs:enumeration value="{x:Null}"/>

    Ideally, we want to represent all the MarkupExtension syntaxes that can be used for these values as well.  Unfortunately, VS' Beta2 XML Editor doesn't support combining enumerations and patterns and still provide suggested values via intellisense.  (It will get better...)


    Validating Schema for System.Windows.Data.BindingMode enum:

    Since we can't add patterns to enumerations and still get intellisense, we could build a validating schema that stops worrying about enumerations for editing niceness, and just tries to be as accurate as possible using patterns.

    <xs:simpleType name="frlrfSystemWindowsDataBindingModeClassTopic">
    xs:restriction base="xs:string">
    xs:pattern value="TwoWay|OneWay|OneTime|Default"/>
          <xs:pattern value="\{Binding.*\}"/>
          <xs:pattern value="\{StaticResource .*\}"/>
          <xs:pattern value="\{DynamicResource .*\}"/>
          <xs:pattern value="\{x:Null}"/>


    Added functionality+Reduced functionality with VS Beta2

    Due to the enumeration + pattern breaking intellisense problem, when you try to set a brush in an attribute, this is the behavior you will see:

    <Button Background="

    will suggest all friendly color names - that is an improvement...we never did that before.

    For now, it will mark #FF0000 or {StaticResource myBrush} as invalid values. That is reduced functionality.  We used to say that Brush was of type xs:string, and had no enums.  So we didn't help you get correctly spelled values, but we never said that a valid syntax was invalid.


    Would love to hear feedback on the decision I made for PDC's schema and any other issues you run into.