views:

336

answers:

1

Hi all xaml-geeks ;)

I've just been fooling around with a ListBox control that I want to style a certain way. For now it looks just like I want it to with rounded corners and no padding. However, the rounded corners seems to cause a problem with the items in the ListBox.

A screenshot so you can see what I mean: alt text

The thing is, that the first and the last item in the listbox needs to have it's corners rounded aswell. So the first item in the listbox needs to have it's upper left and right corners rounded while the bottom corners needs to be rectangular.

Is it possible in some way, to make three different styles and have the first, middle and last items use their own style? So i.e:

  • First item uses style: ListBoxFirstItem
  • Middle items uses style: ListBoxMiddleItems
  • Last item uses style: ListBoxLastItem

Also, as a side question, how am I able to style the selected item and mouse over? If i'd like to get rid of the blue rectangle that's standard.

Hope you understand my question(s), if not - just let me know and I'll see if I can elaborate :)

Thanks in advance!

A: 

what you need is an DataTemplateSelector. this allows you to have different templates for different items in the listbox based on whatever criteria you specify.

check Dr. WPF for a pretty decent example (about 1/2 way down the page)
another tutorial is at Switch On The Code
and everybody's favorite, Bea Stollnitz

Muad'Dib
Hey Muad'Dib, thanks for your reply! :) Greatly appreciated. Million-dollar question here: does DataTemplateSelector also work in Silverlight?
bomortensen
Seems that the ItemTemplateSelector is not present in Silverlight :(
bomortensen
sorry, missed the silverlight part. :(
Muad'Dib
No problem, was me who forgot to tag my question with Silverlight :) Thanks for your help though!
bomortensen