Silverlight - Obtaining ListBox items

6 posts, 0 answers
  1. Rob Lange
    Rob Lange avatar
    23 posts
    Member since:
    Apr 2010

    Posted 13 Apr 2010 Link to this post

    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?
  2. Rob Lange
    Rob Lange avatar
    23 posts
    Member since:
    Apr 2010

    Posted 13 Apr 2010 Link to this post

    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 :)
  3. Missing user
    Missing user avatar

    Posted 13 Apr 2010 Link to this post

    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:

    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.
  4. Jie Liang
    Jie Liang avatar
    1 posts
    Member since:
    May 2010

    Posted 11 Jul 2010 Link to this post

    Hi,

    Are you sure
    TextBlock s = b.Items[b.SelectedIndex].Find.ByType<TextBlock>();
    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


  5. Missing user
    Missing user avatar

    Posted 12 Jul 2010 Link to this post

    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:

    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
  6. Arv
    Arv avatar
    1 posts
    Member since:
    Jun 2010

    Posted 14 Feb 2011 Link to this post

    Got my problem sorted in the end - could not remove my post.

Back to Top