Compiler errors when using the Bindable attribute

It’s been a long break for me from blogging, but I intend to make up for that over the next few months. I’ll primarily be blogging on topics mostly related to using Visual C++ to develop Windows Store applications. So if that’s the sort of thing that interests you, do check back once in a while.

Putting the BindableAttribute on a C++ ref class makes the class available for databinding. Unfortunately, if you add a very simple ref class and then mark it as [Bindable], you’ll get some weird compiler error messages. Example – consider this simple bindable class defined in Restaurant.h.

namespace ViewModels
  public ref class Restaurant sealed

Assume there’s a Restaurant.cpp that includes this file. You’ll get these compiler errors (or something close to it).

Error 1 error C3083: 'ViewModels': the symbol to the left 
    of a '::' must be a type ...\xamltypeinfo.g.cpp 
Error 2 error C2039: 'Restaurant' : is not a member 
    of 'ViewModels' ...\xamltypeinfo.g.cpp 
Error 3 error C2061: syntax error : identifier 
    'Restaurant' ...\xamltypeinfo.g.cpp

The not so obvious fix for these errors is to include Restaurant.h in any of your xxx.xaml.h files (right after the include to the xxx.g.h file would be a good place). This seems to be due to how the XAML compiler ties into the whole build process. Not a major hassle, but more something to be aware of.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s