[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

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 )

Facebook photo

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

Connecting to %s