在我的Windows商店应用程序中,我在名为" BaseClass"的基类中实现属性更改事件。并编写我想绑定到gridview项的属性,然后继承这个基类" BaseClass"在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
{
}
然后我创建了一个Windows :: UI :: Xaml :: Interop :: IBindableObservableVector ^向量,并使用safe_cast从派生类对象追加基类对象。但它没有将基类数据绑定到网格视图,但是当我创建基类对象时,它可以将数据绑定到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.
但
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.
答案 0 :(得分:0)
您可能需要将视图模型注释为bindable:
[Windows::UI::Xaml::Data::Bindable]
ref class DerivedClass: public BaseClass
{
}