I followed https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/resource-dictionaries#stand-alone-resource-dictionaries but i get the error.
XFC0124 Resource "ResourceDictionary1.xaml" not found.
my code is
ResourceDictionary1.xaml (code-behind deleted) compile option: embeded resource
<?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>
I test with the steps provided in the link , everything works fine .
Check the steps below
Add a ContentView
file and rename it ResourceDictionary1 .
Delete code-behind
Remove x:Class="FormsApp.ResourceDictionary1"
in the xaml and change the tag from ContentView
to 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>
<ContentPage.Resources>
<ResourceDictionary Source="ResourceDictionary1.xaml"/>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Button Clicked="Button_Clicked" Text="{StaticResource test}"/>
</StackLayout>
</ContentPage.Content>
If you have done all the steps above and problem persists , it must be something wrong with the file path .
The ResourceDictionary
file should locate at the same level with the page which using the ResourceDictionary.
We can place them at the root of the forms project.
We can place them in same folder .
If they are not in same level , we should set the relative file path in the page .
// in page4.xaml
<ContentPage.Resources>
<ResourceDictionary Source="MyFolder/ResourceDictionary1.xaml"/>
</ContentPage.Resources>