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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:47:06+00:00 2026-06-03T05:47:06+00:00

Maybe here is already such question, but I didn’t find it. I have MVVM

  • 0

Maybe here is already such question, but I didn’t find it.

I have MVVM application, and in my ViewModel I have to do some additional actions on changes of some properties (for example, if View changes them). Which approach is better on your mind and why?

1st – Add AdditionalAction call to setter

public class ViewModel: INotifyPropertyChanged
{
  private int _MyProperty;

  public int MyProperty
  {
    get { return _MyProperty; }
    set
    {
      if (_MyProperty == value) return;
      _MyProperty = value;
      RaisePropertyChanged(() => MyProperty);

      // --- ADDITIONAL CODE ---
      AdditionalAction();
    }
  }
}

2nd – Self-subscribe to INotifyPropertyChanged

public class ViewModel: INotifyPropertyChanged
{
  public ViewModel()
  {
    // --- ADDITIONAL CODE ---
    PropertyChanged += OnPropertyChanged;
  }

  private int _MyProperty;

  public int MyProperty
  {
    get { return _MyProperty; }
    set
    {
      if (_MyProperty == value) return;
      _MyProperty = value;
      RaisePropertyChanged(() => MyProperty);
    }
  }

  void PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
    // --- ADDITIONAL CODE ---
    if (e.PropertyName == "MyProperty")
      AdditionalAction();
  }
}

Imagine, that I don’t have performance problem or 10’000 objects. It’s just View and ViewModel. What is better? First code is “smaller” and has less overhead, but the second (on my mind) is more clear and I can use code snippets for auto-generation properties’ code. Even more – in the 2nd case I can write in event handler something like:

On.PropertyChanged(e, p => p.MyProperty, AdditionalAction);

where On is class-helper.

So, what is better on your mind and why?

UPDATED:

OK, it looks like I found yet one approach:

3rd – add “extension point” in RaisePropertyChanged:

public class NotificationObject : INotifyPropertyChanged
{
  void RaisePropertyChanged(Expression<...> property)
  {
    // ... Raise PropertyChanged event
    if (PropertyChanged != null)
      // blah-blah

    // Call extension point
    OnPropertyChanged(property.Name);
  }

  public virtual OnPropertyChanged(string propertyName)
  {
  }
}

public class ViewModel: NotificationObject
{
  private int _MyProperty;

  public int MyProperty
  {
    get { return _MyProperty; }
    set
    {
      if (_MyProperty == value) return;
      _MyProperty = value;
      RaisePropertyChanged(() => MyProperty);
    }
  }

  override OnPropertyChanged(string propertyName)
  {
    if (propertyName == "MyProperty")
      AdditionalAction();
  }
}

This way we don’t use event, but all “additional actions” are called from the same “extension point”. Is “one place for all addition actions” better than “not transparent workflow”?

  • 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-03T05:47:07+00:00Added an answer on June 3, 2026 at 5:47 am

    I would definitely go for the first method:

    • it’s clear
    • it’s explicit in its flow and intention
    • it avoids weird (imo) self subscription

    The “benefits” of second, which lets you use autogenerated properties is not worth the clearness of the execution flow of the firs case, imo.

    Hope this helps.

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

Sidebar

Related Questions

Maybe is a often repeated question here, but i can't find anything similar with
I asked this question on superuser , but haven't gotten a response. Maybe here
Ok so this maybe a simple/silly question but I don't know so here goes:
There are already some questions about dependency managers here, but it seems to me
It may be a bit too specific, but maybe someone here has experience extending
Maybe I'm thinking about this the wrong way but here's the idea: Class A
maybe it's not so proper to ask this question here... anyway, I'm trying to
I thought I'd post here in the hope that maybe someone with MVVM expertise
I'm new to PHP so maybe I am overlooking something here but the following:
I have another question. Quite similar to the other that i already asked (and

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.