0
namespace Autozite.Entities
{
    public delegate void DimensionInsideChangeEventHandler(Dimension sender, xEventArgs<int> e);

    public class Dimension
    {
        private int _Id;

        public int Id
        {
            get { return _Id; }
            set { _Id = value; OnChange(new xEventArgs<int>(_Size)); }
        }
        private int _Size;

        public int Size
        {
            get { return _Size; }
            set { _Size = value; OnChange(new xEventArgs<int>(_Size)); }
        }
        #region Event On Method
        public event DimensionInsideChangeEventHandler DimensionChange;
        protected virtual void OnChange(xEventArgs<int> e)
        {
            DimensionInsideChangeEventHandler handler = DimensionChange;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        #endregion
    }
}

namespace Autozite.Entities
{
    //Change
    public delegate void DimensionAddadEventHandler(Dimensions sender, xEventArgs<Dimension> e);
    public delegate void DimensionRemovedEventHandler(Dimensions sender, xEventArgs<Dimension> e);
    public delegate void DimensionChangeEventHandler(Dimensions sender, xEventArgs<Dimension> e);

    public class Dimensions : List<Dimension>
    {
        public Dimensions()
        {
        }

        private void Dimensions_DimensionChange(Dimension sender, xEventArgs<int> e)
        {
            throw new NotImplementedException();
        }

        public event DimensionAddadEventHandler DimensionAddad;
        public event DimensionRemovedEventHandler DimensionRemoved;
        public event DimensionChangeEventHandler DimensionChange;
        public new void Add(Dimension dimension)
        {
            base.Add(dimension);
            OnAdded(new xEventArgs<Dimension>(dimension));
            OnChange(new xEventArgs<Dimension>(dimension)); 
        }
        public new void Remove(Dimension dimension)
        {
            base.Remove(dimension);
            OnRemoved(new xEventArgs<Dimension>(dimension));
            OnChange(new xEventArgs<Dimension>(dimension));
        }

        #region Event On Method
        protected virtual void OnAdded(xEventArgs<Dimension> e)
        {
            DimensionAddadEventHandler handler = DimensionAddad;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        protected virtual void OnRemoved(xEventArgs<Dimension> e)
        {
            DimensionAddadEventHandler handler = DimensionAddad;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        protected virtual void OnChange(xEventArgs<Dimension> e)
        {
            DimensionChangeEventHandler handler = DimensionChange;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        #endregion
    }
}

I am trying to control the changes of Dimension object inside Dimensions class derived from List<> with event. but I couldn't write more.

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • 1
    Does this answer your question? [List INotifyPropertyChanged event](https://stackoverflow.com/questions/8470101/liststring-inotifypropertychanged-event) – GSerg Aug 29 '21 at 18:29
  • Does this answer your question? [List of items implementing INotifyPropertyChanged](https://stackoverflow.com/q/11930401/11683) – GSerg Aug 29 '21 at 18:30
  • Thanks for your comments though. I guess this is not the answer I'm looking for. There may be a change event in usercontrol objects. what I want is to trigger an event when the value inside the list changes. – Burak Çelebi Aug 29 '21 at 20:48
  • Looks like INotifyPropertyChanged could solve our problem. but i will gather more information. I've been researching to learn INotifyPropertyChanged a little more deeply. – Burak Çelebi Aug 29 '21 at 20:56

0 Answers0