问题描述
<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# 中做同样的事情,我想我可以做这样的事情,但我意识到我错过了一些东西。知道如何执行此操作的人可以告诉我需要什么吗?
public App()
{
Resources.Add("InverseBool","InverseBool");
例如,我不知道如何为 InverseBool
指定命名空间。
希望有人能帮我解决这个问题。
解决方法
您只需使用 Resources.Add(string key,object value)
Resources.Add("InverseBool",new InverseBool());
当然,您需要包含定义 InverseBool
类的命名空间。