【问题标题】:Binding base class object to Gridview itemSource in windows store app( metro app) c++ not working将基类对象绑定到 Windows 商店应用程序(metro app)中的 Gridview itemSource C++ 不起作用
【发布时间】:2014-04-24 16:58:36
【问题描述】:

在我的 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::IBindableObservableVector^ 向量并使用 safe_cast 从派生类对象附加基类对象。但它没有将基类数据绑定到网格视图,但是当我创建基类的对象时,它可以将数据绑定到网格视图。

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.

【问题讨论】:

    标签: visual-c++ gridview data-binding windows-runtime windows-store-apps


    【解决方案1】:

    您可能需要将视图模型注释为bindable

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

    【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2015-09-05
    相关资源
    最近更新 更多