1
Hello, I’m following you this tutorial and, starting from what it shows along with the Xamarin.Forms documentation, I can create a Resource Dictionary as follows:
<?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="App.Assets.Colors">
<Color x:Key="TestBlue">Blue</Color>
<Color x:Key="TestRed">Red</Color>
<Color x:Key="TestGreen">Green</Color>
</ResourceDictionary>
And with the ResourceDictionary
created, I can call you in any component, including in the global application Resources so:
<?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="App.App">
<Application.Resources>
<ResourceDictionary Source="/Assets/Colors.xaml" />
</Application.Resources>
</Application>
The problem is that when I compile the application to be able to use this resource somewhere in the code, it brings me an error described:
The type 'Color' does not support direct content.
Can someone help me? I have done this in Windows Presentation Forms and I would like to be able to make more flexible the control of variables and extend styles in a simple and dynamic way but it has a good time that I do not research and I do not think how to do...
Can provide an example of where you are trying to use the color?
– Ramon Barbosa
The problem is not to use the color, is to be able to declare it and import it in Xamarin. I made the same code as in Wpf and it still didn’t work
– LeandroLuk
Tried to activate the shampoo build? Put
<?xaml-comp compile="true" ?>
before opening the tag ofResourceDictionary
in your shampoo?– Diego Rafael Souza
No, I didn’t try... To tell you the truth I didn’t even know it existed ... I’ll take a look tomorrow and confirm here if it happened
– LeandroLuk
@Leandroluk, your code should work... there are some differences between the XAML of wpf and Xamarin.Forms, but this is not one of them... Managed to make work by enabling the compilation of XAML?
– Diego Rafael Souza