I'm finding it's much easier said than done... I'm having no trouble grabbing the ListBox, but the Items (ItemCollection) is not giving me the information I'm looking for. When I iterate through the strings, they display the class name of the item in the listbox. I'm looking for the actual string being displayed in the listbox. How can I get that actual string?
5 Answers, 1 is accepted
0
Rob Lange
Top achievements
Rank 1
answered on 13 Apr 2010, 10:26 PM
Time to solve my own problem...
If you run into this problem, you're probably using the 'ItemsSource' ability of your ListBox (ComboBox, etc) with a class you've created.
When WebAii's ItemCollection grabs the System.Windows.Controls.ItemCollection, instead of calling the DisplayMemberPath function, it calls the object.ToString() function on each element. The simple solution is to override the ToString() function. Problem Solved.
Now any UI changes to my Silverlight application fire events back to the main thread of my tests. Validation driven testing on Silverlight. Life is good. Thanks WebAii :)
If you run into this problem, you're probably using the 'ItemsSource' ability of your ListBox (ComboBox, etc) with a class you've created.
When WebAii's ItemCollection grabs the System.Windows.Controls.ItemCollection, instead of calling the DisplayMemberPath function, it calls the object.ToString() function on each element. The simple solution is to override the ToString() function. Problem Solved.
Now any UI changes to my Silverlight application fire events back to the main thread of my tests. Validation driven testing on Silverlight. Life is good. Thanks WebAii :)
0
Hi Rob,
Thanks for the update, I'm glad you got this working. I wasn't sure at first why you were not able to see the Item strings since I checked this on demo pages for ListBox, ComboBox and RadComboBox and was able to see them.
I was going to suggest:
where b is the ListBox/ComboBox/RadComboBox.
Kind regards,
Nelson Sin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Thanks for the update, I'm glad you got this working. I wasn't sure at first why you were not able to see the Item strings since I checked this on demo pages for ListBox, ComboBox and RadComboBox and was able to see them.
I was going to suggest:
TextBlock s = b.Items[b.SelectedIndex].Find.ByType<TextBlock>();
// or
IList<TextBlock> l = b.Find.AllByType<TextBlock>();
where b is the ListBox/ComboBox/RadComboBox.
Kind regards,
Nelson Sin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jie Liang
Top achievements
Rank 1
answered on 11 Jul 2010, 07:02 AM
Hi,
Are you sure
will work?
b.Items[b.SelectedIndex] returns a string, which does not have the Find property. I am using b as a ListBox.
BTW, what is ListBoxItem? It seems that it has nothing to do with ListBox.Items. Maybe I am wrong.
My question is, how to simulate a click on the item in the ListBox?
Thanks,
Jie
Are you sure
TextBlock s = b.Items[b.SelectedIndex].Find.ByType<TextBlock>();
b.Items[b.SelectedIndex] returns a string, which does not have the Find property. I am using b as a ListBox.
BTW, what is ListBoxItem? It seems that it has nothing to do with ListBox.Items. Maybe I am wrong.
My question is, how to simulate a click on the item in the ListBox?
Thanks,
Jie
0
Hi Jie Liang,
Thanks for pointing this out, it looks like what I posted will not work for ListBox.
As a work around, you can try:
Items does seem a little strange in what it returns with respect to ListBox, so I'll try to find out what the collection is for.
Regards,
Nelson
the Telerik team
Thanks for pointing this out, it looks like what I posted will not work for ListBox.
As a work around, you can try:
ListBox b = app.Find.ByType<ListBox>();
IList<ListBoxItem> l = b.Find.AllByType<ListBoxItem>();
l[0].Find.ByType<TextBlock>().User.Click();
// or
b.Find.ByText(
"Item Text"
).User.Click();
Items does seem a little strange in what it returns with respect to ListBox, so I'll try to find out what the collection is for.
Regards,
Nelson
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Arv
Top achievements
Rank 1
answered on 14 Feb 2011, 04:31 PM
Got my problem sorted in the end - could not remove my post.