为什么找不到我的ResourceDictionary xaml文件?

布莱克·西蒙斯

我有一个具有以下结构的Xamarin项目:

MyApp的
 -转换器
 -模型
 -样式
  -Colors.xaml
 -的ViewModels
 -视图
  -ListPage.xaml
   -ListPage.xaml.cs

我正在尝试将Colors.xaml用作我的整个应用程序配色方案的外部资源字典。我已经将源代码添加到“ ListPage.xaml”资源中,如下所示:

    <ContentPage.Resources>
        <ResourceDictionary Source="Styles/Colors.xaml"/>
        <!--<ResourceDictionary>
            <converter:StatusToColorConverter x:Key="StatusToColorConverter" />
        </ResourceDictionary>-->
    </ContentPage.Resources>

当我尝试构建项目时,出现了一些似乎以该错误开头的构建错误
Resource "Styles/Colors.xaml not found.

我已经尝试根据此文档从Colors.xaml文件以及代码隐藏(显然在我的结构中没有一个)文件中删除类标签,但这仍然不能解决问题。我也将相同的内容添加<ResourceDictionary Source="Styles/Colors.xaml"/>到我的App文件中无济于事。为了将ListPage.xaml定向到Colors.xaml文件,我缺少什么?

以下所有相关代码:
Colors.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <!--Color Scheme-->
    <Color x:Key="ColorBackground">#333333</Color>
    <Color x:Key="ColorObjectBackground">#FFFFFF</Color>
    <Color x:Key="ColorTierOneText">#3c3c3c</Color>
    <Color x:Key="ColorTierTwoText">#999999</Color>
</ResourceDictionary>   

ListPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:converter="clr-namespace:MyApp"
             mc:Ignorable="d"
             x:Class="MyApp.Views.ListPage" 
             Title="this is the title">

    <ContentPage.BackgroundColor>
        <OnPlatform x:TypeArguments="Color">
            <On Platform="GTK" Value="#3c3c3c" />
        </OnPlatform>
    </ContentPage.BackgroundColor>

    <ContentPage.Resources>
        <ResourceDictionary Source="Styles/Colors.xaml"/>
        <!--<ResourceDictionary>
            <converter:StatusToColorConverter x:Key="StatusToColorConverter" />
        </ResourceDictionary>-->
    </ContentPage.Resources>

    <StackLayout>
        <Label x:Name="NotFoundMessage"
                   IsVisible="False"
                   Text="No results found."
                   HorizontalTextAlignment="Center"
                   TextColor="ColorTierTwoText"
                   Padding="5"/>
    </StackLayout>  

    </ContentPage.Content>
</ContentPage>

应用程式

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="MyApp.App">


    <Application.Resources>
        <ResourceDictionary Source="Styles\Colors.xaml"/>
    </Application.Resources>
</Application>
莫尔斯

您提供的路径似乎错误Styles\Colors的路径类型仅适用于Android。

要添加外部文件,您需要添加xmlns参考。

并且您缺少x:Class属性。只需像ContentPage一样添加它,然后更改Base类。它必须进行编译才能正常工作。

添加x:Class="MyApp"到Colors.xaml ResourceDictionary属性

<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    x:Class="MyApp">

后面的代码

public partial class Colors : ResourceDictionary
{
    public Colors()
    {
        InitializeComponent();
    }
}

在App.xaml中

xmlns:local="clr-namespace:WhereColorsNamespace."

另外你需要增加使用 MergedDictionary

 <ResourceDictionary.MergedDictionaries>
      <local:Colors x:Key="colors"/>
</ResourceDictionary.MergedDictionaries>

参考:https : //xamarinhelp.com/merged-dictionaries-xamarin-forms/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

cygwin找不到我的文件

来自分类Dev

为什么在我的项目构建中找不到我的jar文件和.war文件?马文

来自分类Dev

为什么smarty模板引擎找不到我的模板文件?

来自分类Dev

Openshift找不到我的CSS文件

来自分类Dev

Webpack找不到我的CSS文件

来自分类Dev

为什么在文件系统中找不到我的SQLite数据库?

来自分类Dev

NSBundle找不到我的plist文件

来自分类Dev

找不到我的文件

来自分类Dev

为什么-classpath找不到我的Jsoup Jar文件?

来自分类Dev

找不到我的文件

来自分类Dev

为什么bash找不到我明确存在的Desktop文件夹?

来自分类Dev

为什么找不到我的文件?[安卓]

来自分类Dev

为什么我的脚本找不到文件?

来自分类Dev

为什么我的for循环找不到任何文件?

来自分类Dev

Rails中的命名约定。为什么在app文件夹中找不到我的服务文件?

来自分类Dev

Windows 8.1为什么找不到我的文件?

来自分类Dev

为什么`find`有时会找到我的文件,有时却找不到

来自分类Dev

发布的项目找不到我的文件

来自分类Dev

为什么找不到我在Android手机上创建的文本文件?

来自分类Dev

NetBeans找不到我的文件

来自分类Dev

为什么wro4j找不到我的main.less文件?

来自分类Dev

为什么 dpkg -i 找不到我的 Minecraft.deb 文件

来自分类Dev

为什么 mdfind 找不到我的 wsdl 文件?

来自分类Dev

为什么powershell找不到我的文件?

来自分类Dev

为什么 BIRTReportGenerator 找不到我的源文件?

来自分类Dev

为什么我收到找不到文件的异常?

来自分类Dev

为什么编译器在有 2 个类的源文件中找不到我的公共类?

来自分类Dev

为什么这个循环找不到我明确存在的文件?

来自分类Dev

当我从 Visual Studio 运行 Jasmine 测试时,为什么 karma 找不到我的 karma.conf.js 文件?

Related 相关文章

  1. 1

    cygwin找不到我的文件

  2. 2

    为什么在我的项目构建中找不到我的jar文件和.war文件?马文

  3. 3

    为什么smarty模板引擎找不到我的模板文件?

  4. 4

    Openshift找不到我的CSS文件

  5. 5

    Webpack找不到我的CSS文件

  6. 6

    为什么在文件系统中找不到我的SQLite数据库?

  7. 7

    NSBundle找不到我的plist文件

  8. 8

    找不到我的文件

  9. 9

    为什么-classpath找不到我的Jsoup Jar文件?

  10. 10

    找不到我的文件

  11. 11

    为什么bash找不到我明确存在的Desktop文件夹?

  12. 12

    为什么找不到我的文件?[安卓]

  13. 13

    为什么我的脚本找不到文件?

  14. 14

    为什么我的for循环找不到任何文件?

  15. 15

    Rails中的命名约定。为什么在app文件夹中找不到我的服务文件?

  16. 16

    Windows 8.1为什么找不到我的文件?

  17. 17

    为什么`find`有时会找到我的文件,有时却找不到

  18. 18

    发布的项目找不到我的文件

  19. 19

    为什么找不到我在Android手机上创建的文本文件?

  20. 20

    NetBeans找不到我的文件

  21. 21

    为什么wro4j找不到我的main.less文件?

  22. 22

    为什么 dpkg -i 找不到我的 Minecraft.deb 文件

  23. 23

    为什么 mdfind 找不到我的 wsdl 文件?

  24. 24

    为什么powershell找不到我的文件?

  25. 25

    为什么 BIRTReportGenerator 找不到我的源文件?

  26. 26

    为什么我收到找不到文件的异常?

  27. 27

    为什么编译器在有 2 个类的源文件中找不到我的公共类?

  28. 28

    为什么这个循环找不到我明确存在的文件?

  29. 29

    当我从 Visual Studio 运行 Jasmine 测试时,为什么 karma 找不到我的 karma.conf.js 文件?

热门标签

归档