WPF popup on ListBoxItem
I have a MiniToolbar popup that shows up at Mouseover on a ListBoxItem, it needs to show just under the item. (a MouseOver trigger also sets the IsSelected property on the items)
I tried two options :
- define the popup on the items DataTemplate
- define the popup on the ControlTemplate for the ListBoxItem
Both options work fine, however I was wondering if the popup was recreated each time ?? (please advise)
I think it would be bet开发者_如何转开发ter to define the popup in the ControlTemplate of the containing ListBox rather than the ListBoxItem ? I tried this, but could not find the binding expression for placement property relative to the SelectedItem (it shows up at the bottom of the ListBox, not bottom of ListBoxItem).
Any suggestions ?
thanks in advance. Michael.
The popup is created one time for each list box item in both cases.
I would not suggest that you use single popup for all items in the CotnrolTemplate for the list box because it significantly complicates things. But if you still want to do so, you can set Placement="Custom"
on you popup and specify CustomPopupPlacementCallback
. In that callback you can calculate the placement using the position of currently selected item.
精彩评论