-2

I have this Base class:

public class MyFileInfo : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    private string _file;
    private int _bytesSent;

    public MyFileInfo(string file)
    {

    }

    public string File
    {
        get { return _file; }
        set { _file = value; }
    }

    public int BytesSent
    {
        get { return _bytesSent; }
        set
        {
            _bytesSent = value;
            OnPropertyChanged("BytesSent");
        }
    }

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

And the derive class:

public class MyFile : MyFileInfo
{
    public MyFile(MyFileInfo myFileInfo)
    }
          this.File = pcapInfo.myFileInfo;
          this.BytesSent = pcapInfo.BytesSent;
    }

    public DoWork()
    {
        // here BytesSent is changing
    }
{

OK so i have the base and the derive class. Inside the derive class my property BytesSent is changing but my UI not. This is my Collection:

private ObservableCollection<MyFile> files{ get; set; }

Maybe i need to define the OnPropertyChanged method in the derive class ?

berry wer
  • 637
  • 2
  • 12
  • 25
  • "Inside the derive class my property BytesSent is changing but my UI not." > What UI? How does it bind? – Patrick Hofman Jul 27 '15 at 14:46
  • 1
    Are you going to post same code over and over again when next problem appears without even *trying* to do it yourself? This is third question in last 2 hours. Seriously, get a book, read it and follow book examples. – Sinatr Jul 27 '15 at 14:52
  • the binding is works fine if MyFile not derive and all this properties is inside MyFile but after derive from MyFileInfo and the properties is defint inside MyFileInfo this stop working – berry wer Jul 27 '15 at 14:53
  • ObservableCollection notifies the binded DependencyProperty (UI) if the collection changed. See https://msdn.microsoft.com/en-us/library/ms668604%28v=vs.110%29.aspx. INotifyPropertyChanged is to notify any UI (DependencyProperty) binded to that property that the property value has changed – Ganesh R. Jul 27 '15 at 14:56
  • Also try moving DoWork in base and see if that works. If no, then deriving is not causing the issue. – Ganesh R. Jul 27 '15 at 14:58

1 Answers1

0

ObservableCollection doesn't notify when properties within the items change. It will only notify you when the list it self changes, such as if an item was added or removed.

Look here for more info: ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)

Community
  • 1
  • 1