UIElementCollection GetItem causes Unspecified Error

According to theSDK on GetItem you should get able to enumerate through the children of a Canvas like:

for (i = 0; i < sender.children.count; i++) {
var child = sender.children.getItem(i);

// Display the index and type of the child object.
alert(i + ": " + child.ToString());
}

However, when I try doing this I'm getting an unspecified error. What I'm doing is creating a canvas object using the downloader object. I'm trying to access one of the children in the new canvas's tree but I'm getting an exception. My code looks like:

var empXaml = this.control.createFromXamlDownloader(sender);


for (i = 0; i < empXaml.children.count; i++)
{
var child = sender.children.getItem(i);
alert(i + ": " + child.ToString());
}

If I put an alert in front of the loop like alert(empXaml.children.count) I get the right number of children. But when I call GetItem(0) (or any valid index number) I get the unspecified error.

I've tried both adding the canvas to the root and then calling these tests and not adding it, both fail. It seems like it should work since I can get the count of children, but for some reason I just can't access the individual items.

I've been testing it in IE7 on Vista 32bit. Thanks.

[1492 byte] By [BryantLikes] at [2007-12-31]
# 1

Did you mean:

for (i = 0; i < empXaml.children.count; i++)
{
var child = empXaml.children.getItem(i);
alert(i + ": " + child.ToString());
}

Just making sure.

Thanks,
Ed Maia
WPF/E Program Manager

EdMaiaMSFT at 2007-9-6 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...