locked
Binding base class object to Gridview itemSource in windows store app( metro app) c++ not working

    Question

  • In my windows store app i implement the property change event in a base class named "BaseClass" and write the properties which i want to bind to my gridview item and i inherit the this base class "BaseClass" in Derived class "DerivedClass". 

        [Windows::UI::Xaml::Data::Bindable]
        ref class BaseClass: Windows::UI::Xaml::DependencyObject, Windows::UI::Xaml::Data::INotifyPropertyChanged
        {
    	public:
    		property Platform::String^ NickName
    		{
    			Platform::String^ get()
    			{
    				return m_strBuddyNickName;
    			}
    			void set(Platform::String^ value)
    			{
    				m_strBuddyNickName = value;
    				OnPropertyChanged("NickName");
    			}
    		}
        }
        
        ref class DerivedClass: public BaseClass
        {
        }

    then i created a Windows::UI::Xaml::Interop::IBindableObservableVector^ vector and append base class object from derived class object using safe_cast. But its not binding the base class data to grid view but when i create an object of base class its can bind the data to gridview.  

        DerivedClass^ derivedClass = ref new DerivedClass();
        BaseClass^ baseClass = safe_cast<BaseClass^>(derivedClass);
    
        Windows::UI::Xaml::Interop::IBindableObservableVector^ m_Vector = ref new Platform::Collections::Vector<BaseClass^>();
        m_Vector->Append(baseClass);
        
        gridview->ItemsSource = m_Vector; // Not binding data to gridview.
    
    but
    
        BaseClass^ baseClass2 = ref new BaseClass();
        Windows::UI::Xaml::Interop::IBindableObservableVector^ m_Vector = ref new Platform::Collections::Vector<BaseClass^>();
        m_Vector->Append(baseClass2);
        
        gridview->ItemsSource = m_Vector; // its Binding data to gridview.

    Friday, April 25, 2014 4:23 AM

All replies

  • Ensure that you have native debugging enabled, then set the WPF Trace Settings/Data Binding to All.  Run the app and see if you have any binding errors.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, April 25, 2014 7:37 PM
    Moderator
  • You can see same post in stack overflow i made i gave the implemented code in comment.

    http://stackoverflow.com/questions/23261300/binding-base-class-object-to-gridview-itemsource-in-windows-store-app-metro-app

    Sunday, April 27, 2014 8:33 AM