Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:04:06+00:00 2026-06-08T01:04:06+00:00

I am learning to use listBox in WPF with dataTemplate using the examples from

  • 0

I am learning to use listBox in WPF with dataTemplate using the examples from MSDN, I can render a listBox bound to an ObservableCollection as a source and by overriding the ToString method.

However, I need to render an image and some texblocks for every item. Here’s my XAML:

<Grid x:Class="MyAddin.WPFControls"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:c="clr-namespace:MyAddin"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Background="Transparent"
             HorizontalAlignment="Stretch" Width="auto"
             Height="215" VerticalAlignment="Stretch" ShowGridLines="False">
    <Grid.Resources>
        <c:People x:Key="MyFriends"/>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBlock HorizontalAlignment="Left" 
               IsManipulationEnabled="True" 
               Height="20" Width="300">Activity Feed</TextBlock>
    <ListBox Grid.Row="1" Name="listBox1" IsSynchronizedWithCurrentItem="True" 
             BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Auto"
             VerticalContentAlignment="Stretch" Margin="0,0,0,5" Background="Transparent">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Border Margin="5" BorderBrush="Black" BorderThickness="1">
                        <Image Source="{Binding Path=Avatar}" Stretch="Fill" Width="50" Height="50" />
                    </Border>
                    <StackPanel Grid.Column="1" Margin="5">
                        <StackPanel Orientation="Horizontal" TextBlock.FontWeight="Bold" >
                            <TextBlock Text="{Binding Path=Firstname }" />
                        </StackPanel>
                        <TextBlock Text="{Binding Path=Comment}" />
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

My Collection class is as following:

public class People : ObservableCollection<Person>
{ }        

public class Person
{
    private string firstName;
    private string comment;
    private Bitmap avatar;

    public Person(string first, string comment, Bitmap avatar)
    {
        this.firstName = first;
        this.comment = comment;
        this.avatar = avatar;
    }

    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }

    public string Comment
    {
        get { return comment; }
        set { comment = value; }
    }

    public Bitmap Avatar
    {
        get { return avatar;}
        set { avatar = value; }
    }

    public override string ToString()
    {
        return firstName.ToString();
    }
}

Once my addin is loaded, I am downloading my data and setting the itemsSource.

People p = new People();
p.Add(new Person("Willa", "Some Comment", myAvatar));
p.Add(new Person("Isak", "Some Comment", myAvatar));
p.Add(new Person("Victor", "Some Comment", myAvatar));

this.wpfControl.listBox1.ItemsSource = p;

The problem I am facing is that the items are being rendered as empty rows whereas If I remove the dataTemplate, the items are rendered fine with their firstName.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:04:07+00:00Added an answer on June 8, 2026 at 1:04 am

    Don’t see anything wrong with the bindings themselves, but your avatar type seems off, WPF expects ImageSource (i do not know if there is any implicit convertion between Bitmap and ImageSource, check for binding errors to find out).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning to use F# to build WPF applications. I using this as reference.
I am learning to use xmlhttprequest/AJAX. In this sample code from w3schools, I do
I'm just learning to use RVM, and would like to know how I can
I am learning to use DelgateCommand from Prism.... In my UI, I have my
I'm learning to use AFNetworking . I know I can use AFHTTPClient for making
I am learning to use Processing , and have modified one of the examples
I'm learning the use of the switch statement and using the rand() and srand()
I have recently started learning wpf and am trying to use mvvm. My understanding
I am learning to use mahout by starting with a example copied from the
I am learning to use styles in wpf and I am creating a style

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.