How do I get the ListBox from a ListBoxItem?

Posted by Shimmy on Stack Overflow See other posts from Stack Overflow or by Shimmy
Published on 2010-04-13T01:01:34Z Indexed on 2010/04/13 1:02 UTC
Read the original article Hit count: 365

Filed under:
|
|
Sub FindAncestor(Of TParent, reference As DependencyObject) As TParent
    'find the parent ListBox container
End Sub

'Usage
Sub Handle(lbi As ListBoxItem)
    Dim lb = GetListBox(lbi)
End Sub

I have a button in a ListBoxItem datatemplate, I want in the handler of the button to access the parent ListBox (this is the way I want to access it, since it's all nested in other DataTemplates, ItemsControls and stuff).

© Stack Overflow or respective owner

Related posts about wpf

Related posts about itemscontrol