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

  • Home
  • SEARCH
  • 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 833649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:33:04+00:00 2026-05-15T04:33:04+00:00

I want to bind a user control (View) to a ListBoxItem. The ListBox is

  • 0

I want to bind a user control (View) to a ListBoxItem. The ListBox is bound to a collection of ViewModels. I have set the ListBox’s ItemTemplate as so:

<ListBox.ItemTemplate>
     <DataTemplate>
           <View:ContactView/>     
     </DataTemplate>
 </ListBox.ItemTemplate>

But all I get are blank ListBoxItems. I can click on them, but nothing is showing visually. My ContactView code is very simply:

<Border>
    <DockPanel>
        <StackPanel DockPanel.Dock="Right" Orientation="Vertical">
            <TextBlock Text="{Binding Path=ContactFirstName, FallbackValue=FirstName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
            <TextBlock Text="{Binding Path=ContactLastName, FallbackValue=LastName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
            <TextBlock Text="{Binding Path=ContactNumber, FallbackValue=Number}" Margin="5, 0, 5, 0"></TextBlock>
        </StackPanel>
    </DockPanel>
</Border>

What could be wrong with this? Thanks.

  • 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-05-15T04:33:04+00:00Added an answer on May 15, 2026 at 4:33 am

    Seem to work fine with my sample project:

    Window1 XAML:

    <Window x:Class="WpfApplication7.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WpfApplication7="clr-namespace:WpfApplication7"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <ListBox x:Name="myListbox">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <WpfApplication7:ContactView/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Window>
    

    ContactView XAML (no code behind needed ;)):

    <UserControl x:Class="WpfApplication7.ContactView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Border>
            <DockPanel>
                <StackPanel DockPanel.Dock="Right" Orientation="Vertical">
                    <TextBlock Text="{Binding Path=ContactFirstName, FallbackValue=FirstName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
                    <TextBlock Text="{Binding Path=ContactLastName, FallbackValue=LastName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
                    <TextBlock Text="{Binding Path=ContactNumber, FallbackValue=Number}" Margin="5, 0, 5, 0"></TextBlock>
                </StackPanel>
            </DockPanel>
        </Border>
    
    </UserControl>
    

    Code behind for Window1:

    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();
            myListbox.ItemsSource = new[]
                                        {
                                            new Contact { ContactFirstName = "Stack", ContactLastName = "Overflow", ContactNumber = 1 },
                                            new Contact { ContactFirstName = "Stack", ContactLastName = "Overflow", ContactNumber = 2 },
                                            new Contact { ContactFirstName = "Stack", ContactLastName = "Overflow", ContactNumber = 3 },
                                        };
        }
    }
    
    public class Contact
    {
        public string ContactFirstName { get; set; }
        public string ContactLastName { get; set; }
        public int ContactNumber { get; set; }
    }
    

    I think your problem lies with the items in your ItemsSource. Make sure you bind to the correct property. My Contact objects have the correct properties. Perhaps your objects in your ItemsSource have different property names? Or do those objects have a property to Contact which holds the properties you want?

    If you have a Contact property in your ItemsSource objects, you can use a binding as follows on the TextBlock (notice the dot):

    <TextBlock Text="{Binding Path=Contact.FirstName}" FontWeight="Bold" Margin="5, 0, 5, 0"></TextBlock>
    

    Hope this helps a bit pin pointing where your problem lies!

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

Sidebar

Related Questions

I have a user control containing a listbox. I want to bind to the
I have a pretty simple user control that I want to bind a ScaleTransform
I have a combobox in a user control and i want to data bind
I have a user control whose users I want to have them set a
If I want to bind a collection to a some form of listing control
Inside my user control I have a collection call Solutions public List<string> Solutions {
I have an ASP.Net user control that contains some checkboxes, and I want to
i have an input element, and i want bind both change and keypress event
I want to bind my UI against a collection of XElements and their properties
I want to bind my ListView control to a generic list of objects? I

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.