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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:18:29+00:00 2026-05-16T08:18:29+00:00

Greetings, creating my first MVVM based WPF app and trying to figure out why

  • 0

Greetings, creating my first MVVM based WPF app and trying to figure out why I’m unable to hook into the PropertyChanged event of a dependency property.

Code in the parent view model:

void createClients()
{
    var clients = from client in Repository.GetClients()
                  select new ClientViewModel(Repository, client);
    foreach (var client in clients)
    {
        client.PropertyChanged += onClientPropertyChanged;
    }
    Clients = new ViewableCollection<ClientViewModel>(clients);
    Clients.CollectionChanged += onClientsCollectionChanged;
}

// Never gets called
void onClientPropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "Name")
    {
         //...
    }
}

ViewableCollection is a simple extension of ObservableCollection to encapsulate a View.

In the ClientViewModel the setters are being called but RaisePropertyChanged isn’t working as I would expect, because onClientPropertyChanged isn’t being invoked. Both view models inherit from ViewModelBase.

public string Name
{
    get { return client.Name; }
    set
    {
        if (value == client.Name) return;
        client.Name = value;
        RaisePropertyChanged("Name");
    }
}

If I wire up PropertyChanged to a method inside the ClientViewModel then it is being fired, so I’m stumped as to why this isn’t working in the parent view model. Where am I going wrong?

  • 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-16T08:18:29+00:00Added an answer on May 16, 2026 at 8:18 am

    This SO question explains the problem; ObservableCollection protects the PropertyChanged event.

    One solution is to use MVVM-Light Messenger:

    void createClients()
    {
        var clients = from client in Repository.GetClients()
                      select new ClientViewModel(Repository, client);
        Clients = new ViewableCollection<ClientViewModel>(clients);
        Clients.CollectionChanged += onClientsCollectionChanged;
        Messenger.Default.Register<PropertyChangedMessage<string>>(this, (pcm) =>
        {
            var clientVM = pcm.Sender as ClientViewModel;
            if (clientVM != null && pcm.PropertyName == "Name")
            {
                // ...
            }
        });
    }
    

    createClients() should be refactored, but for consistency with the question code I’ll leave it in there. Then a slight change to the property setter:

    public string Name
    {
        get { return client.Name; }
        set
        {
            if (value == client.Name) return;
            string oldValue = client.Name;
            client.Name = value;
            RaisePropertyChanged<string>("Name", oldValue, value, true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, In an WPF DataGridTemplateColumn I have a CellTemplate using a ListView and a
Greetings, I have a complicated scenario to handle. I have a wsdl file which
Greetings, I am writing a short simple script, but has became too crowded. Stuff
greetings all i have a domain class named car and i have an object
Greetings, Here is my SConstruct file: env = Environment() env.Append(CCFLAGS=['-g','-pg']) env.Program(target='program1', source= ['program1.c']) Also
Greetings, I am changing the width of an element which serves as a bar
Greetings Everyone I am new in asp.net and i'm using RadControls for Asp.net Ajax
Greetings, I want to import MS Access 2007 table to SQL 2005. I followed
I have a problem to detect when used in GNOME or KDE operating system

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.