Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Desktop

Home Page > Knowledge Base > Rapise > Rapise Web

Article Accessing child components of a WPF / Silverlight ListBox

by Adam S on Thursday, July 18, 2013

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
 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.

Article Info
Last Updated: 7/18/2013
Article ID: KB56
# Views: 3198
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2017 | Licensed to Inflectra Corporation.