iamsophia
iamsophia

Reputation: 796

How can I add application resources to my C# backend for the application instead of in the XAML file?

In my XAML file I have this:

<Application
    x:Class="App"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:converters="clr-namespace:M">
    <Application.Resources>
        <converters:InverseBool x:Key="InverseBool" />
        <Color x:Key="IconAsphalt">#34495E</Color>
    </Application.Resources>
</Application>

To do the same in C# I am thinking I can do something like this but I realize I am missing somethings. Can someone who knows how to do this tell me what is needed?

public App()
{
    Resources.Add("InverseBool", "InverseBool");

I don't know for example how to specify the namespace for InverseBool.

Hope someone can help me with this.

Upvotes: 0

Views: 64

Answers (1)

Cfun
Cfun

Reputation: 9721

You would simply use Resources.Add(string key, object value)

Resources.Add("InverseBool", new InverseBool());

of course you need to include the namespace where your InverseBool class is defined.

Upvotes: 2

Related Questions