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
{
[Windows::UI::Xaml::Data::Bindable]
public ref class Restaurant sealed
{
public:
};
}
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.