views:

187

answers:

1

What is the easiest way to use a valueconverter with a listbox?

I'm setting the ItemSource to a List<> of objects at runtime, and it displays a textstring from the ToString() method. What I would like, though, is to pass the object through a valueconverter to get a completely different string value.

All the examples I have found makes a big deal of binding the list to something in xaml, and defining styles and templates to redesign the whole box, but I just want my values converted...

+6  A: 

Use a data template with something like:

<ListBox.ItemTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter=....}" />
    </...>

That's it. When you don't specify a path in your binding, it simply binds to the current object.

Paul Stovell