Chris in DFW

Hi All,

I have an Expander as part of a ListBoxItem template but I'm having trouble with zindex settings, I think. I need my Expander to render outside the bounds of my ListBoxItem, so I surround it with a Canvas. So far, so good. The problem I have is that the expander gets rendered behind any other list items. I can see that the expansion is happening since the end of the drop down is visible below the last item on the list but I can't seem to find the right zindex setting to make the Expander appear in front of everything else. If it matters, the content of the Expander is another ListBox, which is bound to a DataTable.

I hope that makes sense.

Can anyone help me understand what I'm missing here I've tried increasing zindex on the Expander and on the ListBox it contains but no joy...



Re: Windows Presentation Foundation (WPF) ListBoxItems with Expander and zindex



WPF is based on a container model. That means that each container will control what is shown of its children based on whatever rule is decided, within the area that it is controlling. In case of ListBox, the items are stacked by a panel, which will tell each ListBoxItem where to render and on what size. What you want is to show data outside the boundaries that have been given to the ListBoxItem to display its content, which is not possible. ZIndex won't help either as it will only impact on items within a specific container.

If you want to show data that is overlayed on top of a ListBox, then your elements need to be at the same level or above the ListBox in the element tree. I'm afraid your expander is not going to work the way you are planning.

You could always keep another control that you show above each listboxitem and bind to the same data as your item, and display it by positionnning it at the same location as your listboxitem.

If you had a concrete example of what you're trying to achieve it would be easier to know if it's doable easily in XAML or not :)