#972 – How ListBox Items Are Rendered

The rules for how WPF will render items contained in a ListBox are as follows:

  • If the item derives from UIElement, it is rendered normally, using the layout system
  • Otherwise, the item’s ToString method is called and the resulting string is displayed

In the example below, the first two items in the ListBox derive from UIElement and are therefore rendered as controls.  The third item is a simple .NET object, so its ToString method is called.

        <ListBox Margin="15" Width="250" Height="250">
            <TextBox Text="Enter text here" Width="150"/>
            <Label Content="A label" FontFamily="Times New Roman"
            <local:Actor FullName="Marty Feldman" BirthYear="1934" DeathYear="1982"/>



About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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: