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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:44:10+00:00 2026-06-15T12:44:10+00:00

While reading Pro WPF in C# 2010 the author writes: You can raise an

  • 0

While reading Pro WPF in C# 2010 the author writes:

“You can raise an event for each property. In this case, the event must have the name PropertyNameChanged (for example, UnitCostChanged). It’s up to you to fire the event when the property is changed.”

Could someone confirm this feature works? I was experimenting and not able to reproduce this behavior (I want to see if this works so then I can do some experimenting with System.Reflection.Emit to create dynamic types)

EDIT: I should clarify the emphasis here is to implement change notification WITHOUT implementing INotifyPropertyChanged, as this is what the book is claiming

Here’s the POCO I am testing with:

public class Employee
{
    private string _FirstName;
    public string FirstName 
    {
        get
        {
            return _FirstName;
        }
        set
        {
            if (_FirstName != value)
            {
                _FirstName = value;
                if (FirstNameChanged != null) 
                {
                    FirstNameChanged(this, new PropertyChangedEventArgs("FirstName"));
                }
            }
        }
    }
}

I bound it to a DataGrid and have a timer in the background update the FirstName property randomly every few seconds but the DataGrid never fires

<DataGrid x:Name="dgEmployees" ItemsSource="{Binding ElementName=mainWindow, Path=MyEmployees}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="FirstName" Binding="{Binding Path=FirstName}" />
        </DataGrid.Columns>
    </DataGrid>

The FirstNameChanged event is always null (I thought the binding engine might automatically subscribe to it if it detected it according to the naming convention). MyEmployees is just an ObservableCollection

Can someone confirm if this feature the author mentions, does indeed work and if I’m making a mistake?

EDIT: for the benefit of anyone who thinks I’m misinterpreting the text:

“You can use three approaches to solve this problem:

You can make each property in the Product class a dependency property using the
syntax you learned about in Chapter 4. (In this case, your class must derive from
DependencyObject.) Although this approach gets WPF to do the work for you
(which is nice), it makes the most sense in elements—classes that have a visual
appearance in a window. It’s not the most natural approach for data classes like
Product.

You can raise an event for each property. In this case, the event must have the
name PropertyNameChanged (for example, UnitCostChanged). It’s up to you to
fire the event when the property is changed.

You can implement the System.ComponentModel.INotifyPropertyChanged
interface, which requires a single event named PropertyChanged. You must then
raise the PropertyChanged event whenever a property changes and indicate which
property has changed by supplying the property name as a string. It’s still up to
you to raise this event when a property changes, but you don’t need to define a
separate event for each property.”

  • 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-15T12:44:11+00:00Added an answer on June 15, 2026 at 12:44 pm

    I would say it’s very possible to implement change notifications in your POCO’s without using either INotifyPropertyChanged or dependency properties, like it’s being claimed in the book, unless i’m completely missing the point of the question.

    If you raise an event called {Propertyname}Changed from your POCO when the value of a property has changed, the WPF binding system will pick that up, and update the relevant bindings.

    See this small program for a demonstration – it’s the simplest thing I could think of, but I guess it should work in your case as well.

    XAML:

    <StackPanel>
        <TextBlock Text="{Binding Name}" />
        <Button Content="Change name" Click="changeNameClick" />
    </StackPanel>
    

    Code-behind:

    public partial class Window1 : Window
    {
        private SimpleObject so = new SimpleObject();
    
        public Window1()
        {
            InitializeComponent();
    
            this.so = new SimpleObject();
            so.Name = "Initial value";
    
            this.DataContext = so;
    
            var t = new DispatcherTimer(
                TimeSpan.FromSeconds(1), 
                DispatcherPriority.Normal,
                (s, e) => { this.so.Name = "Name changed at: " + DateTime.Now.ToString(); },
                Dispatcher);
        }
    
        private void changeNameClick(object sender, RoutedEventArgs e)
        {
            this.so.Name = "New value!!";
        }
    }
    
    public class SimpleObject
    {
        private string mName = null;
    
        public string Name 
        {
            get { return mName; }
            set
            {
                if (mName != value)
                {
                    mName = value;
    
                    if (NameChanged != null)
                        NameChanged(this, EventArgs.Empty);
                }
            }
        }
    
        public event EventHandler NameChanged;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reading this class BitmapFactory I noticed that almost all methods inside are static.
While reading the answers to this question I got a doubt regarding the default
While reading proggit today, I came upon this comment in a post about how
While reading this SO post - Is there a version of JavaScript's String.indexOf() that
While reading answers to this question I noticed that answers ( this for example)
While reading some stuff on the pImpl idiom I found something like this: MyClass::MyClass()
While reading this article, I got a doubt. I understood that while trasferring small
While reading this question , I came across @Johannes 's answer. template<typename> struct void_
While reading some SQL Tuning-related documentation, I found this: SELECT COUNT(*) : Counts the
While reading about DataTrigger on MSDN, it says Represents a trigger that applies property

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.