简体   繁体   English

单击按钮时的 colors 列表

[英]List of colors while clicking on button

I am new to the Xamarin forms and I have designed a button my TL asked me, that when we click a button I want to list colors that are to display a color list.I don't know what to do please help someone.我是 Xamarin forms 的新手,我设计了一个按钮,我的 TL 问我,当我们点击一个按钮时,我想列出 colors 来显示颜色列表。

I don't know what your specific needs are, but you can refer to document Listing Colors with BoxView which uses BoxView to achieve this.我不知道您的具体需求是什么,但您可以参考文档Listing Colors with BoxView ,它使用BoxView来实现这一点。

The BoxView is convenient for displaying colors. BoxView便于显示 colors。 This program uses a ListView to list all the public static read-only fields of the Xamarin.Forms Color structure:本程序使用ListView列出Xamarin.Forms颜色结构的所有公共static只读字段:

You can refer to the following code:您可以参考以下代码:

public class NamedColor
{
    // Instance members.
    private NamedColor()
    {
    }

    public string Name { private set; get; }

    public string FriendlyName { private set; get; }

    public Color Color { private set; get; }

    public string RgbDisplay { private set; get; }

    // Static members.
    static NamedColor()
    {
        List<NamedColor> all = new List<NamedColor>();
        StringBuilder stringBuilder = new StringBuilder();

        // Loop through the public static fields of the Color structure.
        foreach (FieldInfo fieldInfo in typeof(Color).GetRuntimeFields ())
        {
            if (fieldInfo.IsPublic &&
                fieldInfo.IsStatic &&
                fieldInfo.FieldType == typeof (Color))
            {
                // Convert the name to a friendly name.
                string name = fieldInfo.Name;
                stringBuilder.Clear();
                int index = 0;

                foreach (char ch in name)
                {
                    if (index != 0 && Char.IsUpper(ch))
                    {
                        stringBuilder.Append(' ');
                    }
                    stringBuilder.Append(ch);
                    index++;
                }

                // Instantiate a NamedColor object.
                Color color = (Color)fieldInfo.GetValue(null);

                NamedColor namedColor = new NamedColor
                {
                    Name = name,
                    FriendlyName = stringBuilder.ToString(),
                    Color = color,
                    RgbDisplay = String.Format("{0:X2}-{1:X2}-{2:X2}",
                                               (int)(255 * color.R),
                                               (int)(255 * color.G),
                                               (int)(255 * color.B))
                };

                // Add it to the collection.
                all.Add(namedColor);
            }
        }
        all.TrimExcess();
        All = all;
    }

    public static IList<NamedColor> All { private set; get; }
}

For more information, you can check the full sample here: ListViewColors :有关更多信息,您可以在此处查看完整示例: ListViewColors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM