[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}" />


About Ramon Tebar

Software Engineer specialised on Microsoft Technologies with experience in large projects for different industrial sectors as developer, consultant and architect. I enjoy designing and developing software applications, it is my job and one of my hobbies. I’m interested in design patterns, new technologies and best practices. Making those part of the ALM process is a great challenge. During the last years, I have specialised in Microsoft Dynamics CRM (now Dynamics 365). I customise and extend the platform to provide tailored solutions and integrations based on service-oriented architectures and messages queuing. Motivated by community events and contributor in blogs, technical books, open source projects and forums, I have been awarded Microsoft Most Valuable Professional (MVP) on Dynamics 365 (CRM) since 2012.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: