如何将Platform :: Collections :: Vector绑定到gridview

时间:2016-10-17 17:24:24

标签: xaml data-binding collections uwp c++-cx

我试图将Platform :: Collections :: Vector绑定到GridView但我得到Visual Studio的编译时错误:

C3986 'get':the signature of the public member contains a native type 'std::equal_to<T>'
C3986 'get':the signature of the public member contains a native type 'std::equal_to<T>'
C3986 'get':the signature of the public member contains a native type 'std::equal_to<T>'
C3986 'get':the signature of the public member contains a native type 'std::equal_to<T>'

NavigationPage.xaml.h

[Windows::Foundation::Metadata::WebHostHidden]
public ref class NavigationPage sealed
{
public:
    NavigationPage();
    property Platform::Collections::Vector<Platform::String^>^ ImagesProperty
    {
        Platform::Collections::Vector<Platform::String^>^ get()
        {
            if (Images == nullptr) Images = ref new Platform::Collections::Vector<Platform::String^>();
            return this->Images;
        };
    }


private:
    Platform::Collections::Vector<Platform::String^>^ Images;
};

NavigationPage.xaml

<GridView Grid.Row="1" x:Name="View" ItemSource="{x:Bind ImagesProperty}">
        <GridView.ItemTemplate>
            <DataTemplate>

            </DataTemplate>
        </GridView.ItemTemplate>
</GridView>

我已经尝试在Google上搜索,但我发现的大部分示例都是使用C#编写的,如果是c ++,则会将目标锁定在Windows 8 / 8.1上,因此我决定在此处询问最后一个资源。

目标版本:10586,最低版本:10586

1 个答案:

答案 0 :(得分:1)

对于那些可能遇到同样问题的人来说,这里是代码,感谢Ed Plunkett发布的链接我能够使它工作,问题是类Platform :: Collections :: Vector(详情在他的链接上)

public:
    NavigationPage();
    property Windows::Foundation::Collections::IObservableVector<Platform::String^>^ ImagesProperty 
    {
        Windows::Foundation::Collections::IObservableVector<Platform::String^>^ get() 
        {
            if (Images == nullptr) Images = ref new Platform::Collections::Vector<Platform::String^>();
            return Images;
        }
    }
private:
    Platform::Collections::Vector<Platform::String^>^ Images;
};

正如您所见,我隐式将Vector类转换为IObservableVector