'MyClass'必须为接口方法'SomeMethod'提供一个实现

时间:2015-09-07 12:04:16

标签: c++-cx uwp

我是Windows编程新手。我用谷歌搜索了这个问题,但是在四到五天内无法解决我的问题。

  

'SpecialistMetro :: SampleData :: AdministrationItem'必须提供接口方法'Windows :: Foundation :: EventRegistrationToken Windows :: UI :: Xaml :: Data :: INotifyPropertyChanged :: PropertyChanged :: add的实现(Windows: :UI :: Xaml :: Data :: PropertyChangedEventHandler ^)'

找到一些信息here但没有用。

我的AdministrationItem.h代码:

namespace SpecialistMetro
{
namespace SampleData
{
    [Windows::Foundation::Metadata::WebHostHidden]
    [Windows::UI::Xaml::Data::Bindable]
    public ref class AdministrationItem : public Windows::UI::Xaml::DependencyObject, public History::IDataSample
    {
    private:
        Platform::String^ _State;
    public:
        virtual Platform::String^ getCustomerId();
        virtual Platform::String^ getSessionId();
        virtual property Platform::String^ State
        {
            Platform::String^ get();
            void set(Platform::String^ value);
        }
        virtual property Platform::String^ ClientName;
        virtual property Platform::String^ OrganizationName;
        virtual property Platform::String^ ClientEmail;
        virtual property Platform::String^ ClientPhoneNumber;
        virtual property Windows::UI::Xaml::Media::SolidColorBrush^ Color;
        virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
        virtual void OnPropertyChanged(Platform::String^ propertyName);
        virtual void UpdateConnectionInfo();
    };
}
}

AdministrationItem.cpp的代码:

#include "pch.h"
#include "AdministrationItem.h"

using namespace SpecialistMetro::SampleData;

Platform::String^ AdministrationItem::State::get()
{
    return _State;
}

void AdministrationItem::State::set(Platform::String^ value)
{
    _State = value;
    OnPropertyChanged("State");
}

Platform::String^ AdministrationItem::getCustomerId()
{
    return "";
}

Platform::String^ AdministrationItem::getSessionId()
{
    return "";
}

void AdministrationItem::UpdateConnectionInfo()
{
}

void AdministrationItem::OnPropertyChanged(Platform::String^ propertyName)
{
    PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(propertyName));
}

1 个答案:

答案 0 :(得分:1)

这条消息解释了它。 AdministrationItem缺少PropertyChangedEventHandler,这是必需的,因为您的AdministrationItem类具有Windows::UI::Xaml::Data::Bindable属性。

event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;

了解更多about the BindableAttribute here

了解如何在此博文中添加活动:Data Binding and C++/CX: INotifyPropertyChanged