如何将应用程序资源添加到应用程序的 C# 后端而不是 XAML 文件中? [英] How can I add application resources to my C# backend for the application instead of in the XAML file?
本文介绍了如何将应用程序资源添加到应用程序的 C# 后端而不是 XAML 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 XAML 文件中,我有这个:
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>
要在 C# 中做同样的事情,我想我可以做这样的事情,但我意识到我错过了一些东西.知道如何执行此操作的人可以告诉我需要什么吗?
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");
例如,我不知道如何为 InverseBool
指定命名空间.
I don't know for example how to specify the namespace for InverseBool
.
希望有人能帮我解决这个问题.
Hope someone can help me with this.
推荐答案
您只需使用 Resources.Add(string key, object value)
Resources.Add("InverseBool", new InverseBool());
当然,您需要包含定义 InverseBool
类的命名空间.
of course you need to include the namespace where your InverseBool
class is defined.
这篇关于如何将应用程序资源添加到应用程序的 C# 后端而不是 XAML 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文