viernes, julio 18, 2008

Silverlight's DropDownList

SL doesn't have a DropDownList. It will in a next release, but while this happen we had to write one ourselves. I tried different options from here and here. The first is a really simple control we used as a basis, the second one is a dll with a lot of control, I only tried the ddl and have to say it had a couple of bugs, didn't worked as expected, specially with databinding.

Get the source code and tests. This is not a complete, fully functional, tested, component, it's simply an easy to use, composite control. The test suite only met what we needed and there might be a lot of uncovered scenarios. Anyway, you can either use it as it is, improve it to meet your need or simply as a rough example on how to do composite controls.

This control has a TextBlock and a Listbox. The listbox is collapsed and it contains the items of the ddl, when the TextBlock is clicked the listbox becomes visible and when the mouse leaves the listBox it's collapsed again. To use it, you can bind something to the control's DataContext and you're done. This will work for the default scenario where you just need to display text for each item and update the text in the TextBlock. The control doesnt support templates, and this is an enhancement you could easily made, simply exposing the listbox templates so you could change, for example, how each item is displayed and databound.

I left my post about the Visual State Manager for tomorrow since I have been asked for the ddl sample in this thread and by e-mail.


No hay comentarios.: