locked
error C2039: is not a member of (after adding [Windows::UI::Xaml::Data::Bindable])

    Question

  • I want to add a class that serves as the data binding source to a combobox control in my C++/XAML project. The properties of the class (name, brush) provide the values for the combobox entries. The definition of the class is

    // ColorMap.h
    #pragma once
    namespace metouch
    {
        [Windows::UI::Xaml::Data::Bindable]
        [Windows::Foundation::Metadata::WebHostHidden]
        public ref class ColorMap sealed
        {
        public:
    	    ColorMap(void);
    	    virtual ~ColorMap(void);
        };
    }
    // ColorMap.cpp
    #include "pch.h"
    #include "ColorMap.h"
    using namespace metouch;
    ColorMap::ColorMap(void)
    {
    }
    ColorMap::~ColorMap(void)
    {
    }

    I get the compile error:

    xamltypeinfo.g.cpp(362): error C2039: 'ColorMap' is not a member of 'metouch'. The 359-363 lines of xamltypeinfo.g.cpp are

    userType->Activator = 
       []() -> Platform::Object^
       {
          return ref new ::metouch::ColorMap();
       }
    The odd thing is if I remove [Windows::UI:Xaml::Data::Bindable] from the definition of the class ColorMap, or remove the source file 'ColorMap.cpp' from the project, this compile error will go away. But neither of the methods is desirable.
    Monday, March 11, 2013 2:15 AM

Answers

  • XamlTypeInfo.g.cpp is a generated file that will include the pch.h header file, the App.xaml.h and App.g.hpp header files, and the *.xaml.h and *.g.hpp header files for each XAML page in your app. The file is generated so that it knows all of the bindable types in your application so that they can be instantiated whenever the XAML parser comes across them.

    If your type (in this case, metouch::ColorMap) isn't somehow included in one of those header files then you will get this error. If you #include your header file ("ColorMap.h") in the pre-compiled header, the App.xaml.h header, or one of the other *.xaml.h header files then it should clear up. (The .g.hpp files are generated so any changes you make to them wouldn't survive.) It's probably best just to #include it in the pch.h header since then the type will be known and accessible in all CPP files and will avoid any issues with compiling the PCH itself.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    • Marked as answer by Leonard Tuesday, March 12, 2013 1:21 PM
    Tuesday, March 12, 2013 2:32 AM

All replies

  • EDITED

    MikeBmcl posted the solution that worked for my issues as well (in my http://PasswrdMgr.Codeplex.com project when trying to use public ICommand properties for data binding)


    MCAD.NET C# - http://www.Global-webnet.com/Blog



    • Edited by BillKrat1 Thursday, March 21, 2013 10:08 AM
    Monday, March 11, 2013 2:07 PM
  • Thank you for your help. I'll try your method tomorrow.
    Monday, March 11, 2013 10:13 PM
  • XamlTypeInfo.g.cpp is a generated file that will include the pch.h header file, the App.xaml.h and App.g.hpp header files, and the *.xaml.h and *.g.hpp header files for each XAML page in your app. The file is generated so that it knows all of the bindable types in your application so that they can be instantiated whenever the XAML parser comes across them.

    If your type (in this case, metouch::ColorMap) isn't somehow included in one of those header files then you will get this error. If you #include your header file ("ColorMap.h") in the pre-compiled header, the App.xaml.h header, or one of the other *.xaml.h header files then it should clear up. (The .g.hpp files are generated so any changes you make to them wouldn't survive.) It's probably best just to #include it in the pch.h header since then the type will be known and accessible in all CPP files and will avoid any issues with compiling the PCH itself.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    • Marked as answer by Leonard Tuesday, March 12, 2013 1:21 PM
    Tuesday, March 12, 2013 2:32 AM