/ / Windowsストアアプリ(メトロアプリ)c ++でベースクラスオブジェクトをGridview itemSourceにバインドする - ビジュアル-c ++、gridview、データバインディング、windows-runtime、windows-store-apps

GridViewのitemSourceにバインドしているbaseSourceは、アプリケーション(メトロアプリ)のC ++が動作しない - visual-c ++、gridview、data-binding、windows-runtime、windows-store-apps

私のWindowsストアアプリで私はプロパティを実装する"BaseClass"という名前の基本クラスのイベントを変更し、私のgridview項目にバインドしたいプロパティを書き、派生クラス "DerivedClass"のこの基本クラス "BaseClass"を継承します。

[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 ::を作成しました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.

回答:

回答№1は0

ビューモデルに次のように注釈を付ける必要があります。 結合可能な

[Windows::UI::Xaml::Data::Bindable]
ref class DerivedClass: public BaseClass
{

}