IanG on Tap

Ian Griffiths in Weblog Form (RSS 2.0)

Blog Navigation

April (2018)

(1 item)

August (2014)

(1 item)

July (2014)

(5 items)

April (2014)

(1 item)

March (2014)

(1 item)

January (2014)

(2 items)

November (2013)

(2 items)

July (2013)

(4 items)

April (2013)

(1 item)

February (2013)

(6 items)

September (2011)

(2 items)

November (2010)

(4 items)

September (2010)

(1 item)

August (2010)

(4 items)

July (2010)

(2 items)

September (2009)

(1 item)

June (2009)

(1 item)

April (2009)

(1 item)

November (2008)

(1 item)

October (2008)

(1 item)

September (2008)

(1 item)

July (2008)

(1 item)

June (2008)

(1 item)

May (2008)

(2 items)

April (2008)

(2 items)

March (2008)

(5 items)

January (2008)

(3 items)

December (2007)

(1 item)

November (2007)

(1 item)

October (2007)

(1 item)

September (2007)

(3 items)

August (2007)

(1 item)

July (2007)

(1 item)

June (2007)

(2 items)

May (2007)

(8 items)

April (2007)

(2 items)

March (2007)

(7 items)

February (2007)

(2 items)

January (2007)

(2 items)

November (2006)

(1 item)

October (2006)

(2 items)

September (2006)

(1 item)

June (2006)

(2 items)

May (2006)

(4 items)

April (2006)

(1 item)

March (2006)

(5 items)

January (2006)

(1 item)

December (2005)

(3 items)

November (2005)

(2 items)

October (2005)

(2 items)

September (2005)

(8 items)

August (2005)

(7 items)

June (2005)

(3 items)

May (2005)

(7 items)

April (2005)

(6 items)

March (2005)

(1 item)

February (2005)

(2 items)

January (2005)

(5 items)

December (2004)

(5 items)

November (2004)

(7 items)

October (2004)

(3 items)

September (2004)

(7 items)

August (2004)

(16 items)

July (2004)

(10 items)

June (2004)

(27 items)

May (2004)

(15 items)

April (2004)

(15 items)

March (2004)

(13 items)

February (2004)

(16 items)

January (2004)

(15 items)

Blog Home

RSS 2.0

Writing

Programming C# 5.0

Programming WPF

Other Sites

Interact Software

Avalon Schema Tweak for ColumnDefinition and RowDefinition

Friday 10 June, 2005, 10:43 PM

When you install the WinFX SDK preview, it provides a few feaures to help with writing Avalon projects in Visual Studio .NET 2005 beta 2. (Collectively these features go by the codename Fidalgo.) It includes an XML schema for XAML documents. You can find this file at C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\Avalon2005.xsd. (Or thereabouts - obviously it depends on where you installed VS.NET 2005 beta 2...)

This schema's job is to provide IntelliSense when you edit XAML files. Its purpose is not to provide a formal definition of how XAML files should be structured. XAML doesn't have a fixed vocabulary because it can be used to work with any number of .NET types. (Contrary to popular perception, XAML isn't tied to Avalon.) Not only is it open to adding new element types, it is also open to extending the set of properties that can be applied to existing elements. Anyone can define new 'attached properties' that can be applied to any element.

This means that any schema definition will tend to hit either of two problems. It might be too restrictive, and disallow documents that are in fact valid XAML. Or it might be too lax, and allow documents that are not valid. A schema that tries to walk the line between these two problems will most likely end up suffering from both...

The schema supplied with Fidalgo exhibits both problems. This isn't a major issue, because the schema file is just there to improve the editing experience - it has no formal significance. However, when the schema falls short, the effect can be quite annoying, because IntelliSense stops working all of a sudden, and you get meaningless warnings when you build.

One problem that has been particularly irksome for me is that the schema doesn't recognize that the Grid lets you put <RowDefinition> and <ColumnDefinition> elements as children of the Grid. Since the Grid is a really useful layout element, I end up not having IntelliSense an awful lot of the time...

One workaround is just to use the verbose syntax. Rather than putting these row/column definition elements directly under the Grid, you can put them inside a <Grid.ColumnDefinitions< or <Grid.RowDefinitions< element. The schema knows about this style, it just doesn't know that the grid lets you omit these as a shorthand.

However, I like the more concise style. So I've hacked my schema so it recognizes this format.

If you'd like to hack your schema, find the definition of the dGrid complex type. This is on line 7064 on my system. It looks like this:

<xs:complexType name="dGrid">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:group ref="cGrid" minOccurs="0"/>
      <xs:any namespace="http://schemas.microsoft.com/winfx/xaml/2005" processContents="strict"/>
      <xs:group ref="gUIElement" minOccurs="0"/>
    </xs:choice>
    ...

I've added the following after that second <xs:group ... >, and before the closing </xs:choice>:

<!-- Hack to allow ColumnDefinition and RowDefinition to be used in line -->
<xs:element name="ColumnDefinition" type="dColumnDefinition" />
<xs:element name="RowDefinition" type="dRowDefinition" />

You'll need to exit VS.NET and restart it for this change to take effect. But from then on, it will accept the more concise grid/column definition syntax without loss of IntelliSense.

Copyright © 2002-2024, Interact Software Ltd. Content by Ian Griffiths. Please direct all Web site inquiries to webmaster@interact-sw.co.uk