none
INotifyPropertyChanged in C++/CLI

    Question

  •  

    When I implement INotifyPropertyChanged  in C++/CLI:

    (public ref class Task : public INotifyPropertyChanged)

    A problem comes to me:

    Error 3 error C3766: 'SomeData' must provide an implementation for the interface method 'void System::ComponentModel::INotifyPropertyChanged::PropertyChanged::add(System::ComponentModel::PropertyChangedEventHandler ^)' 

    I don't know why this error doesn't occur in C# when I implement the INotifyPropertyChanged  ,but occur in C++/CLI .

    Could you so kind to tell me how to resolve it?

    Thank you very much!

    Wednesday, November 29, 2006 9:50 AM

Answers

  • In C++ you don't need to check if the handler is null so the following should work:

    void OnPropertyChanged(String^ info)
    {
        PropertyChanged(this, gcnew PropertyChangedEventArgs(info));
    }
    Friday, December 01, 2006 4:45 AM

All replies

  • No one knows?
    Thursday, November 30, 2006 12:26 AM
  • Did you implement the event? This works for me:

    public ref class Class1 : INotifyPropertyChanged
    {
        public:
            virtual event PropertyChangedEventHandler^ PropertyChanged;
    };
    Thursday, November 30, 2006 4:48 AM
  • But this does not work:

    public ref class Class1 : INotifyPropertyChanged
    {
        public:
            virtual event PropertyChangedEventHandler^ PropertyChanged;
    

      void OnPropertyChanged(String^ info)
      { 
         PropertyChangedEventHandler^ handler= PropertyChanged;//error
               if (handler != nullptr)
               {
                  handler(this, gcnew PropertyChangedEventArgs(info));
               }
      }

    };

    error C3918: usage requires "Task::PropertyChanged' to be a data member 

    Friday, December 01, 2006 12:32 AM
  • In C++ you don't need to check if the handler is null so the following should work:

    void OnPropertyChanged(String^ info)
    {
        PropertyChanged(this, gcnew PropertyChangedEventArgs(info));
    }
    Friday, December 01, 2006 4:45 AM
  • Thank you very much
    Friday, December 01, 2006 6:45 AM