Data Binding in C++ Metro app RRS feed

  • Question

  • I am trying to do data binding in C++ but it does not seem to work.

    I have this property defined in a public ref class CEmployee:

    property String^ Name

    { String^ get() {return _name;}

    void set(String^ value){_name = value;} }

    In my Xaml cpp file I have set the Datacontext in the Ctor appropriately:

    try {

    this->DataContext = ref new CEmployee(); }

    catch(...) { }

    Now, in the xaml code I have set the Button Content to the Name property

     <Button Content="{Binding Name}"></Button>

    This does not work. Any idea why ?
    I quickly went over one example which had [Windows::UI::Xaml::Data::Bindable]on top the the class. So, I went ahead and put it above CEmployee class which resulted in many compile errors.

    Is Data binding supported in C++ in VS 11 Express Beta ? Is there any book planned which covers Metro app development using C++ in depth ?

    • Edited by Shawn Dan Sunday, June 10, 2012 8:33 PM
    Sunday, June 10, 2012 8:31 PM


All replies

  • What sort of compiler errors did you get?


    Monday, June 11, 2012 1:18 PM
  • Hi Nishant,

    If I have [Windows::UI::Xaml::Data::Bindable] placed over my CEmployee class, I am getting CEmployee class is not a member of Application2 (Application2 is my solution namespace name). Error is pionted in xamltypeinfo.g.cpp

    I went over one of the samples using that attribute and they specified client version to be Release preview. Since, I am on consumer preview is that making a difference ?

    Monday, June 11, 2012 5:50 PM
  • Use that header file in any xaml.cpp or xaml.h (for example in MainPage.xaml.cpp).

    Monday, June 11, 2012 7:05 PM
  • Moving the header file to xaml.h solved the issue. Originally, I had it in xaml.cpp file.

    Anyways thanks guys !

    Monday, June 11, 2012 9:59 PM