【问题标题】:Scope of Collections in Winrt And PhotoEditor exampleWinrt 和 PhotoEditor 示例中的集合范围
【发布时间】:2018-08-25 00:06:28
【问题描述】:
  1. Winrt::Windows::Foundation::Collection 只有接口,没有具体的集合类型。

  2. 有人告诉我使用 Platorm::Collections,但不确定您是如何从 Winrt::Windows::????? 获得的。我以为它只适用于 C++/Cx

3.我在 PhotoEditor 示例中复制并使用了 Observable_Vector,但在构建时出现错误,说我的向量类型没有实现 GetTrustLevel()。

  1. 如果我不能在 WInrt 中使用 Platform::Collections,这意味着目前只有一个示例说明如何将集合与 Winrt (PhotoEditor) 一起使用,这也意味着 Winrt 中的唯一具体集合是 phtotEditor 中的 Observable_Vector。李>

需要帮助澄清 c++-Winrt 中的集合范围。 以及在使用来自 PhotoEditor 的相同 Observable_vector 时为什么会出现信任级别错误的任何帮助。

谢谢

【问题讨论】:

  • 好的,我现在可以使用 photoeditor 中的 Observable_Vector 构建我的项目,因为我使用了 Observable_Vector。以前因为我在做 Observable_Vector 得到信任错误。一些新的 Windows 代码代码似乎违反逻辑。在 PhotoEditor 中,我期待 Observable_Vector,但不是 Observable_Vector。不过,解释会有所帮助。
  • 目前还不清楚,问题是什么。 XAML items controls; bind to a C++/WinRT collection 包含有关 Windows 运行时中使用的可观察集合的信息。这些信息可能有助于改进这个问题。

标签: collections uwp c++-winrt


【解决方案1】:

一般来说,您不必实现自己的集合。 C++/WinRT 提供了一组帮助函数,用于创建各种常见的泛型集合类型。例如:

using namespace winrt;
using namespace Windows::Foundation::Collections;

int main()
{
    IVector<int> a = single_threaded_vector<int>({ 1,2,3 });
    IObservableMap<hstring, int> b = single_threaded_observable_map<hstring, int>();
}

还支持创建自定义集合。我在这里描述了其中一些选项:

https://kennykerr.ca/2018/05/12/cppwinrt-creating-collections-simply-efficiently/

【讨论】:

  • 非常感谢,这让我对 winrt 中集合范围的理解更加清晰,至少就矢量和地图而言。请问我在哪里可以找到single_threaded_vector 和single_threaded_observable_map 的任何文档,以及这两个api 所属的winrt 部分的一般文档。例如,我期待在这里看到它们 docs.microsoft.com/en-us/uwp/cpp-ref-for-winrt/winrt 非常感谢您恢复嵌入式 windows c++
  • 感谢您的反馈。我已经要求我们的文档作者添加这些内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-29
  • 2017-11-18
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 2022-11-02
  • 2017-06-10
相关资源
最近更新 更多