You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2015中Xamarin.Forms页面报错:Property Resources为空或非IEnumerable

解决Xamarin.Forms中XamlParseException: Property Resources is null or is not IEnumerable错误

我之前在做Xamarin.Forms项目时也碰到过一模一样的错误,这个问题的核心原因很明确:Xamarin.Forms要求应用资源必须放在ResourceDictionary容器中,如果你的Application.Resources节点下直接写注释或者资源定义,没有嵌套ResourceDictionary,解析器就会认为Resources属性是无效的可枚举集合,从而抛出这个异常。

看你提供的App.xaml代码片段,<Application.Resources>后面直接跟了注释,缺少了关键的ResourceDictionary节点,这就是问题的根源。

修正步骤

  1. 给Application.Resources添加<ResourceDictionary>子节点,所有应用级资源都要放在这个节点内部
  2. 如果你有需要合并的外部资源字典,要放在ResourceDictionary.MergedDictionaries里,不能直接放在Application.Resources下

修正后的完整App.xaml示例

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Bisells.App">
    <Application.Resources>
        <!-- 必须嵌套ResourceDictionary节点 -->
        <ResourceDictionary>
            <!-- 在这里添加你的应用资源,比如样式、颜色、模板等 -->
            <Color x:Key="PrimaryColor">#2196F3</Color>
            <Style x:Key="ButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="{StaticResource PrimaryColor}" />
                <Setter Property="TextColor" Value="White" />
            </Style>
            
            <!-- 如果有合并资源字典,放在这里 -->
            <!--<ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>-->
        </ResourceDictionary>
    </Application.Resources>
</Application>

额外排查点

  • 检查ResourceDictionary的拼写是否正确,别写错成ResourceDictionay这类低级错误
  • 确保所有资源定义(比如Color、Style、ControlTemplate等)都在ResourceDictionary内部,不能直接作为Application.Resources的子元素
  • 做完修改后,清理项目并重新生成解决方案,有时候VS的缓存会导致解析异常残留

内容的提问来源于stack exchange,提问作者Beingnin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:22:45