【问题标题】:How to bind Platform::Collections::Vector to a gridview如何将 Platform::Collections::Vector 绑定到 gridview
【发布时间】:2017-02-26 18:49:24
【问题描述】:

我试图将 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

【问题讨论】:

  • 这是否解决了问题? stackoverflow.com/a/11770357/424129
  • 好吧,我在实现 Windows::Foundation::Collections::IVector 时遇到了麻烦,但是根据你的回答,我可以假设其余代码在语法上没问题吗?
  • 我对 C++ 太生疏了,无法对此发表评论。
  • 问题已解决,感谢您的帮助:D
  • 除非此问题与 EdPlunkett 链接的问题重复,否则您应该添加答案(有关更多信息,请参阅 Can I answer my own question?)。

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


【解决方案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

【讨论】:

  • 您收到错误是因为 Platform::Vector 是实现 IVector 的具体 C++ 类型。 XAML 中的集合在绑定到 IVector 时将在内部尝试转换为 IBindableObservableVector 类型(在他们了解如何绑定的接口中),这是专门为支持 C++/CX 数据绑定方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
  • 2014-02-24
  • 2011-09-16
  • 2014-07-29
  • 2011-06-05
  • 2013-06-12
相关资源
最近更新 更多