How to bind static resource from dictionary in android colors.xml

218 Views Asked by At

I'm using .NET Maui and I defined a static resource in Colors.xaml file, like so:

<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary 
   xmlns="http://schemas.microsoft.com/dotnet/2021/maui"   
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
   <Color x:Key="Primary">#47D1C1</Color>
</ResourceDictionary>

Now I want to bind it in colors.xml file defined for Android platform. How can I do it? Here is the Android colors.xml file:

    <?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="colorPrimary"> here I want to bind Primary resource </color>
   <color name="colorPrimaryDark">??</color>
   <color name="colorAccent">??</color>
</resources>
1

There are 1 best solutions below

0
Guangyu Bai - MSFT On

They are two different xml files for the different platforms. They can not bind the data from each other. If you want to Theme an app you can use the ResourceDictionary.