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

  • Home
  • SEARCH
  • 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 3215156
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:08:41+00:00 2026-05-17T15:08:41+00:00

I have searched high and low for a solution but I dont seem to

  • 0

I have searched high and low for a solution but I dont seem to get to the bottom of it.
Like many posts on the net I dont seem to make my itemPropertyChanged work.
It does not fire when editing an item in the collection.Why.

a bit lenghty but this is an example I have put together.

I have a customerViewModel that contains a Collections of OrderViewModels
when editing the order in the datagrid the event does not fire.

I have implemented the following but never gets fired when editing only when loading.
As if it’s not the same collection of something…

INotifyPropertyChanged inpc = OrderViewModels;
inpc.PropertyChanged += OnItemPropertyChanged; 

Any suggestions?It’s driving me mad

Models

public class Order
{
    public int Id { get; set; }
    public string Description { get; set; }
    public int CustomerId{ get; set; }
}

public class Customer
{
    public Customer()
    {
        Orders=new ObservableCollection<Order>();
    }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Surname{ get; set;}
    public ObservableCollection<Order> Orders{ get; set;}

}

ViewModels

public class CustomerViewModel : ViewModelBase
{
    private Customer _customerModel;

    public CustomerViewModel(Customer customerModel)
    {
        _customerModel = customerModel;
        _orderViewModels = new ObservableCollection<OrderViewModel>();
        OrderViewModels.CollectionChanged += OnOrdersCollectionChanged;
        INotifyPropertyChanged inpc = OrderViewModels;
        inpc.PropertyChanged += OnItemPropertyChanged; 

    }

    private void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        //not firing!!!!!!!!!!!!!!!!!!!!!!!!!
    }

    void OnOrdersCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        switch (e.Action)
        {
            case NotifyCollectionChangedAction.Add:
                _customerModel.Orders.Insert(e.NewStartingIndex, ((OrderViewModel)e.NewItems[0]).OrderModel);
                break;
            case NotifyCollectionChangedAction.Remove:
                _customerModel.Orders.RemoveAt(e.OldStartingIndex);
                break;
            case NotifyCollectionChangedAction.Replace:
                _customerModel.Orders[e.OldStartingIndex] = ((OrderViewModel)e.NewItems[0]).OrderModel;
                break;
            case NotifyCollectionChangedAction.Move:
                _customerModel.Orders.Move(e.OldStartingIndex, e.NewStartingIndex);
                break;

            default:
                throw new ArgumentOutOfRangeException();
        }
    }

    public int Id
    {
        get { return _customerModel.Id; }
        set
        {
            _customerModel.Id = value;
            OnPropertyChanged("Id");
        }
    }

    public string Name
    {
        get { return _customerModel.Name; }
        set
        {
            _customerModel.Name = value;
            OnPropertyChanged("Name");
        }
    }

    public string Surname
    {
        get { return _customerModel.Surname; }
        set
        {
            _customerModel.Surname = value;
            OnPropertyChanged("Surname");
        }
    }
    public Customer CustomerModel
    {
        get { return _customerModel; }
        set
        {
            _customerModel = value;
            OnPropertyChanged("");
        }
    }

    private ObservableCollection<OrderViewModel> _orderViewModels;

    public ObservableCollection<OrderViewModel> OrderViewModels
    {
        get { return _orderViewModels; }
        set
        {
            _orderViewModels = value;
            OnPropertyChanged("OrderViewModels");
        }
    }
}

public class OrderViewModel:ViewModelBase
{
    private Order _orderModel;

    public OrderViewModel(Order orderModel)
    {
        _orderModel = orderModel;
    }

    public int Id
    {
        get { return _orderModel.Id; }
        set
        {
            _orderModel.Id = value;
            OnPropertyChanged("Id");
        }
    }
    public int CustomerId
    {
        get { return _orderModel.CustomerId; }
        set
        {
            _orderModel.CustomerId = value;
            OnPropertyChanged("CustomerId");
        }
    }
    public string Description 
    {
        get { return _orderModel.Description; }
        set
        {
            _orderModel.Description = value;
            OnPropertyChanged("Description");
        }
    }

    public Order OrderModel
    {
        get { return _orderModel; }
        set
        {
            _orderModel = value;
            OnPropertyChanged("");
        }
    }
}

Repository

public class OrderRepository
{
    public static ObservableCollection<Order> GetOrders(int customerId)
    {
        return new ObservableCollection<Order>
               {
                   new Order {Id = 1, CustomerId=1, Description = "MotherBoard"},
                   new Order {Id = 2, CustomerId=1,Description = "Video Card"},
                   new Order {Id = 3, CustomerId=1,Description = "TV"},
                   new Order {Id = 4, CustomerId=1, Description = "Video Recorder"},
                   new Order {Id = 5, CustomerId=1,Description = "Speakers"},
                   new Order {Id = 6, CustomerId=1,Description = "Computer"}
               };
    }
}

View

public partial class OrdersView
{
    public OrdersView()
    {
        InitializeComponent();

        if (!DesignerProperties.GetIsInDesignMode(this))
        {
            var customerVm =
                new CustomerViewModel(new Customer
                                          {
                                              Id = 1,
                                              Name = "Jo",
                                              Surname = "Bloggs"
                                          });

            var orders = OrderRepository.GetOrders(1);
            foreach (var orderModel in orders)
            {
                customerVm.OrderViewModels.Add(new OrderViewModel(orderModel));
            }
            DataContext = customerVm;
        }
    }
}

Xaml

<Grid>
    <DataGrid AutoGenerateColumns="False" AlternationCount="2" ItemsSource="{Binding Path=OrderViewModels}">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Id}" Header="Id"/>
            <DataGridTextColumn Binding="{Binding CustomerId}" Header="Customer Id"/>
            <DataGridTextColumn Header="Description" Binding="{Binding Description,UpdateSourceTrigger=PropertyChanged}"/>
        </DataGrid.Columns>
    </DataGrid>
</Grid>
  • 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-17T15:08:42+00:00Added an answer on May 17, 2026 at 3:08 pm
        INotifyPropertyChanged inpc = OrderViewModels;
        inpc.PropertyChanged += OnItemPropertyChanged; 
    

    That code will notify you when any property on the ObservableCollection<T> changes, not when items in the ObservableCollection<T> have their properties changed. For example, your handler should be called when you add or remove an OrderViewModel because the Count property will change on the ObservableCollection<OrderViewModel>.

    Nothing is propagating the PropertyChanged event inside OrderViewModels and aggregating them into a single event for you. I use a class I called ItemObservableCollection when I want to do this:

    public sealed class ItemObservableCollection<T> : ObservableCollection<T>
        where T : INotifyPropertyChanged
    {
        public event EventHandler<ItemPropertyChangedEventArgs<T>> ItemPropertyChanged;
    
        protected override void InsertItem(int index, T item)
        {
            base.InsertItem(index, item);
            item.PropertyChanged += item_PropertyChanged;
        }
    
        protected override void RemoveItem(int index)
        {
            var item= this[index];
            base.RemoveItem(index);
            item.PropertyChanged -= item_PropertyChanged;
        }
    
        protected override void ClearItems()
        {
            foreach (var item in this)
            {
                item.PropertyChanged -= item_PropertyChanged;
            }
    
            base.ClearItems();
        }
    
        protected override void SetItem(int index, T item)
        {
            var oldItem = this[index];
            oldItem.PropertyChanged -= item_PropertyChanged;
            base.SetItem(index, item);
            item.PropertyChanged += item_PropertyChanged;
        }
    
        private void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            OnItemPropertyChanged((T)sender, e.PropertyName);
        }
    
        private void OnItemPropertyChanged(T item, string propertyName)
        {
            var handler = this.ItemPropertyChanged;
    
            if (handler != null)
            {
                 handler(this, new ItemPropertyChangedEventArgs<T>(item, propertyName));
            }
        }
    }
    
    public sealed class ItemPropertyChangedEventArgs<T> : EventArgs
    {
        private readonly T _item;
        private readonly string _propertyName;
    
        public ItemPropertyChangedEventArgs(T item, string propertyName)
        {
            _item = item;
            _propertyName = propertyName;
        }
    
        public T Item
        {
            get { return _item; }
        }
    
        public string PropertyName
        {
            get { return _propertyName; }
        }
    }
    

    I can use it like this:

    var orders = new ItemObservableCollection<OrderViewModel>();
    orders.CollectionChanged   += OnOrdersChanged;
    orders.ItemPropertyChanged += OnOrderChanged;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched high and low but can't get this to work. TextView topic
I have searched the knowledge base high and low, but nothing seems to give
I've searched high and low, but I could not find a solution, to what
I have searched high and low, but I can't figure this one out. I
I have searched high and low to try and get the Product Advertising API
I have searched high and low for a solution. I have both linecache19 and
I have searched high and low, but have found very little to achieve my
I have searched high and low for this solution. Any insights will be highly
I have searched high and low (and very possibly could have missed it), but
I have searched high and low and tried various patterns but it seems I

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.