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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:26:16+00:00 2026-06-05T21:26:16+00:00

When I have a class that implements INotifyPropertyChanged, is it ok to expose the

  • 0

When I have a class that implements INotifyPropertyChanged, is it ok to expose the implementation as a public method?

For instance, if I have a property called “Sum” on a class, and I want a button click in the UI to update the sum, what is the best way to do this?

Below is some pseudo-code to illustrate what I mean

classinstance.NotifyPropertyChanged("Sum");
...
public Sum { 
   get { return x + y + z; }
}
  • 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-05T21:26:17+00:00Added an answer on June 5, 2026 at 9:26 pm

    In .Net the preferred practice for methods that raise events is for the method to be declared as protected so that it can only be called by derived classes (This is because only the class that declares the event can raise it. In order to raise the event from a derived class a method is required to raise the event).

    For example…

    protected void OnPropertyChanged(string propertyName)
    {
        var handler = this.PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    This method is then called by the class (or derived classes) in a property setter to indicate that a property has changed, like so…

    public object MyProperty
    {
        get { return _myProperty; }
        set
        {
            _myProperty = value;
            OnPropertyChanged("MyProperty");
        }
    }
    

    Other objects can then subscribe to this event and will be notified every time the MyProperty property is changed.

    Now, to answer your question as to whether the OnPropertyChanged method can be public. The answer is yes but you should be asking yourself why this would be the case.

    Why would another class know when a property has changed so that it can call the method? if it already ‘knows’ when the property has changed then you shouldn’t need to subscribe to the property changed event in the first place! Only the class itself should ‘know’ when one of its own properties has changed.

    In your example You are notifying that the property ‘sum’ has been changed. but it hasn’t. In fact, your code doesn’t even allow that property to be changed outside of its own class.

    I suspect that maybe you want some way of notifying that the sum property needs to be re-evaluated because a dependent property has been changed. If this is the case then you need to raise a property changed event when that dependent property changes.

    Imagine that changes to the ‘MyProperty’ property shown earlier also means that ‘Sum’ has changed then that would be handled like this:

    // This property is used by the 'sum' property so if this changes
    // clients need to know that 'sum' has also changed.
    public object MyProperty
    {
        get { return _myProperty; }
        set
        {
            _myProperty = value;
            OnPropertyChanged("MyProperty");
            OnPropertyChanged("Sum");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that implements INotifyPropertyChanged for a property. I have a control
I have the following method in a base class that implements System.ComponentModel.INotifyPropertyChanged: protected virtual
I have a class Bar that implements INotifyPropertyChanged. When setting the property CurrentFoo, I
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor
I have a class in .NET that implements IXmlSerializable. I want to serialize its
I have a class that implements the INotifyPropertyChanged interface. Some of the properties of
I have a class Seive that implements INotifyPropertyChanged. I have a ObservableCollection SeiveList.I input
I have a data class that implements INotifyPropertyChanged and two WPF controls that DataBind

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.