【问题标题】:Why does Xamarin ListView Cahcing Strategy show "Ambiguous Reference"?为什么 Xamarin ListView 缓存策略显示“不明确的引用”?
【发布时间】:2016-11-04 05:45:25
【问题描述】:

下面是“核心”项目中一个页面的屏幕截图。添加CachingStrategy="RecycleElement" 时,我收到一个

“不明确的引用”错误。

将鼠标悬停在它上面不会提供任何关于如何修复它的额外信息,ReSharper 也不会。

【问题讨论】:

  • 你修好了吗?
  • 不幸的是,没有。花了 3~4 天把头发扯下来,但没有运气。
  • 我似乎无法用 XVS 4.2.1.60 和 XF 2.3.2 重现这一点。你能确认这些版本吗?
  • 尝试了几个版本的 Xamarin,都出现同样的错误。当前运行最新,它仍然显示相同的错误。
  • 分享复制此示例的 .zip。我似乎无法重现。另外,请从 VS 发布您的完整版本信息,也许它是您拥有的一些扩展,例如 Resharper。

标签: xaml xamarin xamarin.forms


【解决方案1】:

您可以在 ListView 构造函数中指定 RecycleElement 而不是使用 x:Arguments

<ListView ...>
  <x:Arguments>
    <ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy>
  </x:Arguments>
</ListView>

【讨论】:

    【解决方案2】:

    ReSharper 根本无法看到该属性,因为 it does not really exist or at least ReSharper is not able to detect it(请阅读该段落让 Xamarin 这么说)。 Xamarin Forms 做了一些棘手的事情(我认为他们使用 PInvoke 或编译器技巧,但不太记得),当代码被编译时,为了在指定该属性并且 ReSharper 不知道它时更改您的 ListView 代码继续。希望 ReSharper 将在更新中解决此问题,但我不确定他们是否会这样做。

    【讨论】:

      【解决方案3】:

      使用上述方法时显示 "Error CS0234 The type or namespace name 'CachedListView' does not exist in the namespace 'Xamarin.Forms' (are you missing an assembly reference?)" 是否需要添加 x:Arguments?或者是否有必要提供参考

      xmlns:local ="clr-namespace:TestProject.Data"
      

      【讨论】:

      • 我用了上面的方法也遇到同样的错误,如果解决了请告诉我,谢谢
      【解决方案4】:

      添加类

      public class CachedListView : ListView
      {
          public CachedListView() : base(ListViewCachingStrategy.RecycleElement) { }
      }
      

      在 Xaml 中使用 CachedListView 代替 ListView。

      【讨论】:

        猜你喜欢
        • 2016-03-18
        • 1970-01-01
        • 2019-03-03
        • 1970-01-01
        • 1970-01-01
        • 2023-03-22
        • 2010-10-06
        • 2020-05-08
        • 2013-07-28
        相关资源
        最近更新 更多