How do you scroll a Silverlight List control?

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

How do you scroll a Silverlight List control?

Post by Aracknid » Fri Sep 10, 2010 9:55 pm

Hi,

I have a Silverlight List control. Within the List are many ListItems. Each ListItem has a child CheckBox and a Text element.

I've not done any testing using Ranorex outside of this Silverlight control, so I'm not sure if my problems are related only to Silverlight or the way in which our developers implemented it, or if these problems would also occur in non-Silverlight controls.

So here is my issue. When I iterate through the List control's ListItems, it cannot "see" the items in the list that are outside the List control (actually it sees one or 2 of them, but not the rest).

I figure that I have to scroll the List control to force them to display, but I cannot figure out how to do that.

I had a quick look a a general List control (The IE Language Preferences dialog), and in The Ranorex Spy it had a scrollbar element that I assume you could manipulate. This ScrollBar element doesn't appear in the Ranorex Spy for the Silverlight control, even though there is on on the screen.

How do I make it scroll, or is there another way to get the ListItems not displayed?

Thanks,

Matt.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How do you scroll a Silverlight List control?

Post by Support Team » Mon Sep 13, 2010 8:40 am

Hi Matt,

Would it be possible to post us a Ranorex Snapshot of the corresponding control?
http://www.ranorex.com/support/user-gui ... html#c2072
The items which are not in the viewable area should be displayed as "visible=false" in Spy.
And could you post us which version of Ranorex is in use?

Thanks in advance.
Regards,
Peter
Ranorex Team

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How do you scroll a Silverlight List control?

Post by Aracknid » Mon Sep 13, 2010 3:07 pm

OK, I will send support (via e-mail) all the requested info. I don't won't to post specifics about my application in a public forum.

I'm using the trial version, 2.3.3.8879 (according to the studio app which I'm not using). I only use the API and the spy tool.

Aracknid.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How do you scroll a Silverlight List control?

Post by Support Team » Tue Sep 14, 2010 8:14 am

Hi,

I will answer then your email.

Regards,
Peter
Ranorex Team

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How do you scroll a Silverlight List control?

Post by Aracknid » Tue Sep 14, 2010 3:22 pm

Based on our e-mails, here was the issue and the resolution.

I have a List control which contains multiple ListItems. Each ListItem had a child Checkbox and aTextbox. The list control allowed you to turn on or off columns in a table.

To scroll the ListItem into view, I simply needed to use the EnsureVisible method.

I did try this at first, and it failed. But the reason it failed was not because it wasn't scrolling the ListItem into view. It was because the code after was attempting to look at the Checkbox to see if it was checked on or off. Because the code was going faster than the Silverlight control could load and render the next ListItem, my code would fail.

To resolve this, I simply added a small delay after the EnsureVisible method.

E.G.
Public Function Get_ShowColumns() As Collection

        Dim MyList As Ranorex.List
        Dim MyListItem As Ranorex.ListItem
        Dim MyCollection As New Collection
        Dim MyCheckbox As Ranorex.CheckBox
        Dim MyText As Ranorex.Text

        Try

            MyList = MyFields(Fields_ManageViewsDialog.Field_List_ShowHideColumns).sRxPath

            For Each MyListItem In MyList.Items

                'This forced the ListItem into view and the delay allowed the SilverLight list control time to render
                 MyListItem .EnsureVisible() 
                Delay.Milliseconds(150)

                If MyListItem.Children.Count <> 2 Then 'There is no checkbox and textbox...
                    Return Nothing
                End If

                MyCheckbox = Adapter.Create(Of Ranorex.CheckBox)(MyListItem.Children.Item(0).Element)
                MyText = Adapter.Create(Of Ranorex.Text)(MyListItem.Children.Item(1).Element)

                If MyCheckbox.Checked Then
                    MyCollection.Add(MyText.TextValue, MyText.TextValue)
                End If

            Next

            Return MyCollection

        Catch e As RanorexException
            Return Nothing
        Catch e As Exception
            Return Nothing
        End Try

    End Function
Thanks,

Aracknid.