Stupid ListBox tricks.
I finally found a way to accomplish one of the lamest limitations of ListBox- that there's no way to change the Z-order of items. This pops up so many times- everyone wants to make a ListBox whose contents scale when selected. The item scaling up should be on top of its siblings, but there's been no way to do this since the next item in the ListBox is by definition higher and would overdraw the previous item. Re-ordering of the children is disallowed by the ItemsControl, so it's we've always thought it was impossible to change the Z-order.
I realized the other evening that you don't actually have to reorder the items- just pretend to. Enter overriding GetVisualChild- all that needs to be done is to subvert this call and return the selected item last. Voila.
Sample is complete with nice in-out animations.
Source & Sample
I finally found a way to accomplish one of the lamest limitations of ListBox- that there's no way to change the Z-order of items. This pops up so many times- everyone wants to make a ListBox whose contents scale when selected. The item scaling up should be on top of its siblings, but there's been no way to do this since the next item in the ListBox is by definition higher and would overdraw the previous item. Re-ordering of the children is disallowed by the ItemsControl, so it's we've always thought it was impossible to change the Z-order.
I realized the other evening that you don't actually have to reorder the items- just pretend to. Enter overriding GetVisualChild- all that needs to be done is to subvert this call and return the selected item last. Voila.
Source & Sample
6 Comments:
Hi, I think this is a very nice sample. Unfortunately it does not run on February 2006 CTP. There are a lot of errors I could not rid of them. Is there any possibility to update the sample. Appreciate that. Irina
irina.natliashvili@alconlabs.com
Great article! Thanks.
Thanks for interesting article.
Nice! Nice site! Good resources here. I will bookmark!
I see first time your site guys. I like you :)
Excellent website. Good work. Very useful. I will bookmark!
Post a Comment
<< Home