[WPF] Custom Listbox (description and source code)

WPF allows to create custom controls with flexibility. In this case, I’ll show you a custom Listbox with the follow interesting features:

  • Resizeable (listbox and its items)
  • Custom items with text and picture
    • Mouse over effect with custom color
    • Selected item with custom background color
  • Items Source from Binding. In my example, I’ve used a collection of “Customer” objects to fill the elements of the listbox, simulating that they are provided by a external service, as well as each picture is a array of bytes inside of “Customer” type.
  • Custom converters in binding fields:
    • To fill each picture (array of bytes) in a Image object

<Image  Margin="2" Stretch="Uniform"  Source="{Binding Path=Image,Converter={StaticResource LocalByteArrayToImageConverter}}"/>

    • To format the address in line. Address is another custom type “Address” inside of “Customer”. Using another converter, we can take the desired fields that we want to show and how we want to do it

<TextBlock Text="{Binding Path=FullAddress, Converter={StaticResource LocalAddressToFullAddressConverter}}"  Style="{StaticResource TextBlockContentStyle}" />

DOWNLOAD CODE HERE

Advertisements

Posted on October 30, 2009, in WPF. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: