属性资源为null或不是IEnumerable

时间:2018-04-06 09:43:11

标签: xaml xamarin.forms

当我在学习制作Xamarin.Forms页面时,我在visual studio 2015中以中断模式出现此错误。

  

未处理的例外情况:   Xamarin.Forms.Xaml.XamlParseException:位置12:10。属性资源为null或不是IEnumerable

我的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>

        <!-- Application resource dictionary -->
        <!--  colors  -->
        <!--<Color x:Key="HeaderTextColor">#585858</Color>
            <Color x:Key="BodyTextColor">#C3C3C3</Color>-->

        <Color x:Key="TimelineColor">#E4B6C3</Color>
        <Color x:Key="HeaderTextColor">#3C3C3C</Color>
        <Color x:Key="BodyTextColor">#869EAC</Color>
        <Color x:Key="TimeColor">#A64C79</Color>

        <!--  font families  -->
        <OnPlatform
                x:Key="RegularFontFamily"
                x:TypeArguments="x:String"
                Android="sans-serif"
                iOS="HelveticaNeue" />
        <OnPlatform
                x:Key="LightFontFamily"
                x:TypeArguments="x:String"
                Android="sans-serif-light"
                iOS="HelveticaNeue-Light" />
        <OnPlatform
                x:Key="MediumFontFamily"
                x:TypeArguments="x:String"
                Android="sans-serif-medium"
                iOS="HelveticaNeue-Medium" />

        <!--  fonts  -->
        <Font
                x:Key="HeaderFont"
                FontFamily="{StaticResource MediumFontFamily}"
                FontSize="30" />
        <Font
                x:Key="SubHeaderFont"
                FontFamily="{StaticResource MediumFontFamily}"
                FontSize="18" />
        <Font
                x:Key="TitleFont"
                FontFamily="{StaticResource MediumFontFamily}"
                FontSize="20" />
        <Font
                x:Key="BodyFont"
                FontFamily="{StaticResource RegularFontFamily}"
                FontSize="18" />


        <!--  styles  -->
        <Style x:Key="PageHeaderLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
            <Setter Property="Font" Value="{StaticResource HeaderFont}" />
        </Style>

        <Style x:Key="SubHeaderLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
            <Setter Property="Font" Value="{StaticResource SubHeaderFont}" />
        </Style>

        <Style x:Key="ClassTimeLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource TimeColor}" />
            <Setter Property="Font" Value="{StaticResource TitleFont}" />
        </Style>

        <Style x:Key="ClassNameLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource HeaderTextColor}" />
            <Setter Property="Font" Value="{StaticResource TitleFont}" />
        </Style>

        <Style x:Key="ClassInstructorLabel" TargetType="Label">
            <Setter Property="TextColor" Value="{StaticResource BodyTextColor}" />
            <Setter Property="Font" Value="{StaticResource BodyFont}" />
        </Style>
    </Application.Resources>
</Application>

xamarin也没有显示出现异常的位置

2 个答案:

答案 0 :(得分:3)

您忘记了ResourceDictionary代码:

<Application.Resources>
    <ResourceDictionary>
        <!-- Application resource dictionary -->
        <!--  colors  -->
        <!--<Color x:Key="HeaderTextColor">#585858</Color>
            <Color x:Key="BodyTextColor">#C3C3C3</Color>-->

        <Color x:Key="TimelineColor">#E4B6C3</Color>
        <Color x:Key="HeaderTextColor">#3C3C3C</Color>
        <Color x:Key="BodyTextColor">#869EAC</Color>
        <Color x:Key="TimeColor">#A64C79</Color>
    </ResourceDictionary>
 </Application.Resources>

答案 1 :(得分:1)

在App.xaml中定义样式,如下所示:

<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="PlatformFontSample.App">
<Application.Resources>
    <ResourceDictionary>
        <OnPlatform x:Key="FontFamilyName" x:TypeArguments="x:String" iOS="MarkerFelt-Thin" Android="OpenSans" WinPhone="Segoe UI" />
        <Style x:Key="FontLabel" TargetType="Label">
            <Setter Property="FontFamily" Value="{DynamicResource FontFamilyName}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

然后在xaml中使用:

<Label Text="{Binding Name}" Style="{DynamicResource FontLabel}" FontSize="Medium" FontAttributes="Bold" LineBreakMode="NoWrap"/>