When you have a WPF or Silverlight application that has a list box (or other control that supports templates such as a Tree) that has an item template that contains sub-controls, you may need to access the individual controls rather than just the entire list item. This article outlines the approach for doing this.

The attached zipfile includes a sample application that contains a sample WPF application with a list-box that contains three textblocks for each item. The sample script traverses the items in the list and each of the controls in each item.

We use a custom function to access the controls:

function DumpUIAChildren(objRule, rootObj)
{
 Tester.Message("Name: "+objRule.objectName(rootObj)+" objectClass: "+objRule.objectClass(rootObj));
 
 // Learn the child as 'SeSObject'. Now we can use standard methods (Do... Get... Set...)
 var sesObj = SeSTryMatch(rootObj);
 // .highlight() is undocumented but very useful
 sesObj.highlight();
 sesObj.DoMouseMove(10,10);
 
 var ccount = objRule.childCount(rootObj);
 Tester.Message("# of children: "+ccount);
 
 for(var i=0;i<ccount;i++)
 {
  var childObj = objRule.childAt(rootObj, i);
  DumpUIAChildren(objRule, childObj);
 }
}

Once you have this function added to the Test.user.js file you can use it with your learned ListBox object:

 var list = SeS('List');
 DumpUIAChildren(list.rule, list.instance);

The full source code is in the attached zipfile.

Attachments

Selected files will be attached to any email sent on saving ticket.

file selected files selected  () Delete Selected

  • Created:
  • by:

Select files to upload

Or drag and drop files here

Uploading …
Done!
Upload More?
There was an error.
Try again?

Save to upload the selected file(s)

Article Info
  • Last Updated: 7/18/2013
  • Article ID: KB56
  • Views: 3712