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 6183079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:18:24+00:00 2026-05-24T01:18:24+00:00

If I create a class that extends WPF’s ListBoxItem, create a list of these

  • 0

If I create a class that extends WPF’s ListBoxItem, create a list of these objects, try to bind the list to a ListBox’s ItemsSource, the items will not display:

<ListBox ItemsSource="{Binding Path=LbData, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
    <ListBox.ItemTemplate>
        <DataTemplate >
            <TextBlock Text="{Binding Path=Display}" Margin="1" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
public partial class MainWindow : Window
{
    public IEnumerable lbData = new List<LbItem>();
    public IEnumerable LbData
    {
        get { return lbData; }
        set { lbData = value; }
    }

    public MainWindow()
    {
        InitializeComponent();
        LbData = new List<LbItem> { new LbItem("a"), new LbItem("b") };
    }
}

public class LbItem : ListBoxItem
{
    public string Display { get; private set; }

    public LbItem(string v)
    {
        Display = v;
    }
}

I’m new to WPF and don’t see why this should be an issue. TIA

  • 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-24T01:18:24+00:00Added an answer on May 24, 2026 at 1:18 am

    The ItemsSource normally is used for data-objects, and what you do there (setting the ItemTemplate) suggest that you should not make your object inherit from ListBoxItem at all, instead it should be a normal object (possibly implementing INotifyPropertyChanged if properties may change after creation). If the list changes it should implement INotifyCollectionChanged.

    Because the items are already ListBoxItems the DataTemplate you set will be disregarded. There should be the following error in your Visual Studio Output-window:

    System.Windows.Data Error: 26 : ItemTemplate and ItemTemplateSelector are ignored for items already of the ItemsControl’s container type; Type=’LbItem’

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

Sidebar

Related Questions

I'm trying to create a class that extends input stream Clojure via gen-class .
I have create a class MyConnection that extends NSURLConnection. I have implemented some delegate
I need to create my own class that extends Hash and append the additional
I have class that extends AsyncTask class and I create instance of this class
I have create a class that extends BaseAdapter . At the same time, tt
I'm attempting to create a class that extends a CursorAdapter in order to display
I'm a starter at Java. I'd like to create a Form class that extends
I create class that extends LinerLayout and add many elements on view, also I
I need to create a base class that extends Activity which does some common
I created a class that extends ProfileBase: public class CustomerProfile : ProfileBase { public

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.