C++ compiler errors in xamltypeinfo.g.cpp

Posted by Richard Banks on Stack Overflow See other posts from Stack Overflow or by Richard Banks
Published on 2012-03-21T23:21:23Z Indexed on 2012/03/21 23:30 UTC
Read the original article Hit count: 696

Filed under:
|
|
|
|

I must be missing something obvious but I'm not sure what.

I've created a blank C++ metro app and I've just added a model that I will bind to in my UI however I'm getting a range of compiler warnings related to xamltypeinfo.g.cpp and I'm not sure what I've missed.

My header file looks like this:

#pragma once
#include "pch.h"
#include "MyColor.h"

using namespace Platform;

namespace CppDataBinding
{
    [Windows::UI::Xaml::Data::Bindable]
    public ref class MyColor sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
    {
    public:
        MyColor();
        ~MyColor();

        virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
        property Platform::String^ RedValue
        {
            Platform::String^ get()
            { 
                return _redValue;
            }
            void set(Platform::String^ value)
            {
                _redValue = value;
                RaisePropertyChanged("RedValue");
            }
        }

    protected:
        void RaisePropertyChanged(Platform::String^ name);

    private:
        Platform::String^ _redValue;
    };
}

and my cpp file looks like this:

#include "pch.h"
#include "MyColor.h"

using namespace CppDataBinding;

MyColor::MyColor()
{
}

MyColor::~MyColor()
{
}

void MyColor::RaisePropertyChanged(Platform::String^ name)
{
    if (PropertyChanged != nullptr)
    {
        PropertyChanged(this, ref new  Windows::UI::Xaml::Data::PropertyChangedEventArgs(name));
    }
}

Nothing too tricky, but when I compile I get errors in xamltypeinfo.g.cpp indicating that MyColor is not defined in CppDataBinding.

The relevant generated code looks like this:

if (typeName == "CppDataBinding.MyColor")
{
    userType = ref new XamlUserType(this, typeName, GetXamlTypeByName("Object"));
    userType->Activator = ref new XamlTypeInfo::InfoProvider::Activator(
                            []() -> Platform::Object^ 
                            { 
                                return ref new CppDataBinding::MyColor(); 
                            });
    userType->AddMemberName("RedValue", "CppDataBinding.MyColor.RedValue");
    userType->SetIsBindable();
    xamlType = userType;
}

If I remove the Bindable attribute from MyColor the code compiles.

Can someone tell me what blindingly obvious thing I've missed so I can give myself a facepalm and fix the problem?

© Stack Overflow or respective owner

Related posts about c++

Related posts about xaml