Bug of "LayerIDs" property of the "Legend" control?

726
4
01-13-2012 03:31 AM
HugoCardenas
New Contributor
My Visual Studio 2010 design breaks with the following XAML code:
<esri:Legend Map="{Binding ElementName=MyMap}" LayerIDs="Points of Interest, United States" LayerItemsMode="Tree"/>


In fact, it is the property "LayerIDs" which breaks it.  This is the exception I get:

Unable to cast object of type 'Microsoft.Expression.DesignModel.DocumentModel.DocumentPrimitiveNode' to type 'Microsoft.Expression.DesignModel.DocumentModel.DocumentCompositeNode'.
   at Microsoft.Expression.DesignModel.InstanceBuilders.ArrayInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.Expression.DesignModel.Core.ViewNodeManager.Instantiate(ViewNode viewNode)


After doing some research, I found out that the "LayerIDs" property references an integer array, rather than a collection; referencing a strong typed integer collection solves the problem.  Someone reported this bug (referencing an integer array) at the Microsoft site; the bug has been reported to this link:

http://connect.microsoft.com/VisualStudio/feedback/details/655799/defining-a-property-that-reference...

The workaround (setting the collection) is also posted here:
http://connect.microsoft.com/VisualStudio/feedback/details/655799/defining-a-property-that-reference...

Here "rex_hansen" (3/31/2011 at 3:51 PM) has been kind enough to post a project "ArrayXAMLDemo" to show how to construct the strong-typed collection to be referenced by a property similar to "LayerIDs".  I really do not have access to the "LayerIDs" property original code to make the change; I do not know how to inherit from the "Legend" control to make the change on the derived control either.  Please, if you know how a workaround, do let me know.

Thanks!
Hugo.
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
Note that the bug impacts the design only. There is no issue when compiling and running the project.

The easiest workaround is to set the LayersIDs by code (for example on loaded event).

Subclassing the control should work as well but you can't reuse the same property name. You have to create a new property that is setting the underlying 'LayerIDs' property by code.
0 Kudos
HugoCardenas
New Contributor
Thanks Dominique!
I set the property with code-behind as advised (cf. below) and it works well (the design time Visual Studio 2010 exception went away).

XAML code now (notice the "LayerIDs" is not present at design time):
<esri:Legend x:Name="mapLegend" Map="{Binding ElementName=MyMap}" LayerItemsMode="Tree"/>


C# code behind at onload page sets the "LayerIDs" property:
public MainPage()
{
  InitializeComponent();

  . . .

  mapLegend.LayerIDs = new string[] { "Meters", "Hydrants", "WaterLines" };
}
0 Kudos
AnastasiaAourik
New Contributor II
Hi All,   Thought I should comment / inquire regarding this.

comment:
I just have ignored the VS2010 error and build the solution; It still works and generates my Legend for the layers I specify in LayerIDs="aaa,bbb,ccc" in the XAML.

question:
Can someone tell me if this is 'dangerous' or if someone at esri can explain why it still works.

Thanks,
anastasia
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Can someone tell me if this is 'dangerous' or if someone at esri can explain why it still works.


The bug occurs only at design time, we never noticed any problem at run time (it works because there is a type converter converting comma separated strings to an array of string).
0 Kudos