IList in Expression Blend Designer

by Weifen Luo (DevZest) 17. December 2009 09:31

Recently an user of WPF Dockingreported a bug that in Expression Blend the sample window is not rendering. The Blend window says "Invalid XML", the error message in the results pane says:
The property "ShowActions" can only be set once;
The property "ShowActions" does not have an accessible setter;
The specified value cannot be assigned. The following type was expected: "ShowActionCollection"".

The ShowActions property is of type ShowActionCollection, which is a collection implements IList (only IList.Add is implemented, all other implementation just throws NotSupportedException).  It works fine in Visual Studio, but apparently Expression Blend treat this property as a normal property, not collection.

So I decided to make a sample application to reproduce this behavior. I created a StringCollection class which implements IList (only IList.Add is implemented, all other implementation just throws NotSupportedException), a CustomElement class contains a Strings property of type StringCollection to draw the strings, and a Window contains the CustomElement. The error is reproduced:

IListError

After hours of trying with different options, the problem is finally solved:

IListNoError

  1. The IList.Add must be implemented implicitly. That is, StringCollection must have a public Add method instead of explicitly implement IList.Add. This is really weird, but this is the way how Expression Blend designer works.
  2. The IList.Clear, IList.IsFixedSize and IList.IsReadOnly must be properly implemented. Expression Blend designer calls these methods to render, if an exception is thrown, you will end up with “Invalid XAML” with the exception message in the result pane.

Tags:

WPF | Expression Blend

Comments

12/17/2009 10:14:32 AM #

IList in Expression Blend Designer

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com |

Comments are closed

Copyright DevZest, 2008 - 2014