xaml - 未找到独立 ResourceDictionary 资源
问题描述
XFC0124 找不到资源“ResourceDictionary1.xaml”。
我的代码是
ResourceDictionary1.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">
<x:String x:Key="test">
test string
</x:String>
</ResourceDictionary>
ContentPage1.xaml
<ContentPage.Resources>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
</ContentPage.Resources>
解决方案
我使用链接中提供的步骤进行测试,一切正常。
检查以下步骤
添加一个
ContentView
文件并将其重命名为 ResourceDictionary1 。删除代码隐藏
在 xaml 中删除
x:Class="FormsApp.ResourceDictionary1"
并将标记从 更改ContentView
为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:String x:Key="test">
test string
</x:String>
</ResourceDictionary>
- 在其他 xaml 中的用法
<ContentPage.Resources>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Button Clicked="Button_Clicked" Text="{StaticResource test}"/>
</StackLayout>
</ContentPage.Content>
如果您已完成上述所有步骤,但问题仍然存在,则一定是文件路径有问题。
该ResourceDictionary
文件应与使用 ResourceDictionary 的页面位于同一级别。
// in page4.xaml
<ContentPage.Resources>
<ResourceDictionary Source="MyFolder/ResourceDictionary1.xaml"/>
</ContentPage.Resources>
推荐阅读
- c++ - 有没有办法搜索和复制所有的 DLL 依赖项?
- javascript - 如何使用角度js在切换开关内添加关闭文本
- javascript - 角度单击表格标题以对行进行排序
- javascript - 如何在样式中获得反应动态背景图像值?
- maven - jacoco 在报告中包括 apache
- reactjs - 如何为不包含参数的相关资源定义 react-query 查询键
- python - 按降序排序字符串列表(根据长度)
- c# - 如何在 ASP.NET MVC 中执行控制器后将数据发送到操作筛选器?
- git - 恢复 git reset 软
- python-3.x - 在numpy unpack中将字符串转换为日期