Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Grabbing Item Properties on Databound Listbox
4 replies. Latest Post by murtaza.dharwala on January 16, 2009.
(0)
ihilder
Member
4 points
8 Posts
01-16-2009 12:46 PM |
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
226 points
38 Posts
01-16-2009 1:30 PM |
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....
Participant
1659 points
378 Posts
01-16-2009 1:42 PM |
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
01-16-2009 2:02 PM |
That worked perfect. There really needs to be an easy way to reference elements of a ListBox if it is databound.
01-16-2009 2:23 PM |
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