【发布时间】:2021-04-09 12:06:04
【问题描述】:
您好,我当前的 xamarin 应用程序没有全局 App.xaml 文件,只有一个 App.cs,这是我配置它的方式,并希望保持这种方式。
现在的问题是,我想使用一些来自 fontawsome 的字体图标,但为此我需要定义一个可以在 xaml 文件中使用的资源字典。现在我正在将资源复制粘贴到我需要图标的每个 xaml 页面。
我希望资源能够在全球范围内工作,所以有没有办法可以将我的代码转换为 C# 或在我的全局 App.xaml 文件中实现资源,这样我就不必一直复制/粘贴它。
这是我用于资源的代码:
<ResourceDictionary>
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeBrands">
<On Platform="Android"
Value="FontAwesome5Brands.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Brands-Regular" />
<On Platform="UWP"
Value="/Assets/FontAwesome5Brands.otf#Font Awesome 5 Brands" />
</OnPlatform>
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeSolid">
<On Platform="Android"
Value="FontAwesome5Solid.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Free-Solid" />
<On Platform="UWP"
Value="/Assets/FontAwesome5Solid.otf#Font Awesome 5 Free" />
</OnPlatform>
<OnPlatform x:TypeArguments="x:String"
x:Key="FontAwesomeRegular">
<On Platform="Android"
Value="FontAwesome5Regular.otf#Regular" />
<On Platform="iOS"
Value="FontAwesome5Free-Regular" />
<On Platform="UWP"
Value="/Assets/FontAwesome5Regular.otf#Font Awesome 5 Free" />
</OnPlatform>
</ResourceDictionary>
【问题讨论】:
-
到目前为止你有没有尝试过?
-
是的谷歌搜索没有结果我试图将代码转换为 c# 但它根本不起作用
标签: c# wpf xamarin xamarin.forms resourcedictionary