Skip to main content

Microsoft Silverlight

Answered Question Grabbing Item Properties on Databound ListboxRSS Feed

(0)

ihilder
ihilder

Member

Member

4 points

8 Posts

Grabbing Item Properties on Databound Listbox

Here is an earlier post for reference of the code that I'm currently working with here.  I'm trying to grab the ActualWidth of the a HyperlinkButton at a specific position in the Listbox.  Programatically referencing a databound ListBox only returns a collection of the type of object that are bound to it.  How would I go about referencing something like the ActualWidth in a case like this?  Thanks in advance.

-Ian

 

peluchejs
peluchejs

Member

Member

226 points

38 Posts

Re: Grabbing Item Properties on Databound Listbox

You can use VisualTreeHelper to walk down the visual tree and get the actual HyperlinkButton that was created for each element. I'm assuming that you're doing this programmatically, since you want the HyperlinkButton at a specific position. It's not the most elegant solution since it does involve your app logic knowing an awful lot about your UI, but AFAIK this is currently the only way to get the actual visual items that were generated.

murtaza.dharwala
murtaza....

Participant

Participant

1659 points

378 Posts

Answered Question

Re: Grabbing Item Properties on Databound Listbox

you can try one thing

i guess you must be using a datatemplate

and u r having your hyperlink control over there

the trick is attach the loaded event handler to the hyperlink

and  in the event handler add the hyperlink refrence which u have with sender, in a List<Hyperlink>

later when user selects the item from the listbox based on the selected itemindex retrieve the hyperlink from the list

and then you can acess the properties

 

Murtaza Dharwala
Diaspark Inc.
www.diaspark.com
email:murtaza.dharwala@diaspark.com


Please remember to click “Mark as Answer” on the post that helps you

ihilder
ihilder

Member

Member

4 points

8 Posts

Re: Grabbing Item Properties on Databound Listbox

 That worked perfect.  There really needs to be an easy way to reference elements of a ListBox if it is databound.

 

murtaza.dharwala
murtaza....

Participant

Participant

1659 points

378 Posts

Re: Grabbing Item Properties on Databound Listbox

please mark it as an answer

another thing u have to care about is if u remove items from the listbox then u wil need proper calculation also

Murtaza Dharwala
Diaspark Inc.
www.diaspark.com
email:murtaza.dharwala@diaspark.com


Please remember to click “Mark as Answer” on the post that helps you
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities