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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:47:07+00:00 2026-06-04T23:47:07+00:00

I cannot get any display from my observable collection in a custom object bound

  • 0

I cannot get any display from my observable collection in a custom object bound to a ListBox. This works fine when I have a string collection in my view model, but no names display when I try to access the property through a custom object. I am not receiving any errors in the output window.

Here is my code:

Custom Object

public class TestObject
{
    public ObservableCollection<string> List { get; set; }

    public static TestObject GetList()
    {
        string[] list = new string[] { "Bob", "Bill" };

        return new TestObject
        {
            List = new ObservableCollection<string>(list)
        };
    }
}

Xaml

<Window x:Class="TestWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ListBox Height="100" HorizontalAlignment="Left" Margin="120,61,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Path=TObj.List}" />
</Grid>

Xaml.cs

    public partial class MainWindow : Window
{
    private ModelMainWindow model;

    public MainWindow()
    {
        InitializeComponent();
        model = new ModelMainWindow();
        this.DataContext = model;
        this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
    }

    public void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.model.Refresh();
    }
}

ViewModel

    public class ModelMainWindow : INotifyPropertyChanged
{
    private TestObject tObj;

    public event PropertyChangedEventHandler PropertyChanged;

    public TestObject TObj
    {
        get
        {
            return this.tObj;
        }

        set
        {
            this.tObj = value;
            this.Notify("Names");
        }
    }

    public void Notify(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }

    public void Refresh()
    {
        this.TObj = TestObject.GetList();
    }
}
  • 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-04T23:47:09+00:00Added an answer on June 4, 2026 at 11:47 pm

    Can’t bind to private properties. Also the change notification targets the wrong property, change "Names" to "TObj". (Also i would recommend making the List property get-only (backed by a readonly field), or implementing INoptifyPropertyChanged so the changes cannot get lost)

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

Sidebar

Related Questions

I cannot get the returning data from the server to display on my form
When I use below code query database, I cannot get any result, but I
I am having many problems running DJ. Primarily, I cannot get delayed_job running any
Searching for possible ways to get cookie with httpOnly enabled, I cannot find any.
I cannot get the DropDownHeight of the ComboBox set properly to display all the
This seems like a very simple problem, but I cannot get a scrollbox to
I would like to get some information from a website. I have already got
I cannot seem to get a message from drupal_set_message when a user registers on
I get this issue in ICS, but not in previous versions: From App1, I
From my understanding of PHP documentation, setting custom error handler (which cannot catch all

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.