xamarin - 如何在 Xamarin 中创建 ResourceDictionary?

标签 xamarin xamarin.forms

我正在尝试遵循这个例子:

public class App : Application
{
    public App ()
    {
        var buttonStyle = new Style (typeof(Button)) {
            Setters = {
                ...
                new Setter { Property = Button.TextColorProperty,   Value = Color.Teal }
            }
        };

        Resources = new ResourceDictionary ();
        Resources.Add ("buttonStyle", buttonStyle);
        ...
    }
    ...
}

Global Styles

但它不起作用/无法识别new ResourceDictionary()。有谁知道我可能做错了什么?

最佳答案

您也可以将 setter 添加到样式的 Setters 集合中。 PCL 中的代码:

        using Xamarin.Forms; 

        .....
        this.Resources = new ResourceDictionary();
        var style = new Style(typeof(Button));
        style.Setters.Add(new Setter { Property = Button.TextColorProperty,   Value = Color.Teal });

        Resources.Add("MyButtonStyle", style);

关于xamarin - 如何在 Xamarin 中创建 ResourceDictionary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45281369/

相关文章:

c# - 'Gravity' 不包含 'CENTER_HORIZONTAL' 的定义

c# - 使用 .net Framework 4.6.1 而不是项目框架 .netstandard 版本 2 恢复包 Microsoft.Net.Http - Xamarin Form

xamarin.forms - Xamarin.Forms UWP TabbedPage 中的选项卡图标?

azure - 没有 Cosmos DB 图形数据库模拟器

c# - xamarin 跨平台 Canvas

c# - 显示有关未处理异常的对话框

android - 在 Xamarin Forms 中访问 AssetManager

c# - Xamarin.Forms [0 :] Binding: MobileUI. Models.RootObject 无法转换为类型 'System.Collections.IEnumerable'

azure - 无法将 Microsoft.Azure.Mobile.Server.Authentication 安装到 Xamarin Forms 中

c# - Httpclient multipart/form-data 同时发布图片和json