You might need to annotate your view model as bindable:
[Windows::UI::Xaml::Data::Bindable]
ref class DerivedClass: public BaseClass
{
}
質問
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
{
}
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.
解決
You might need to annotate your view model as bindable:
[Windows::UI::Xaml::Data::Bindable]
ref class DerivedClass: public BaseClass
{
}