Ejemplo n.º 1
0
 private static HighlightingBrush ParseColor(string color)
 {
     if (string.IsNullOrEmpty(color))
     {
         return(null);
     }
     return(FixedColorHighlightingBrush((Color?)ColorConverter.ConvertFrom(null, null, color)));
 }
        /// <summary>
        /// 文字列を Color に変換します
        /// </summary>
        /// <param name="value">文字列</param>
        /// <param name="targetType">変換後の型</param>
        /// <param name="parameter">パラメータ</param>
        /// <param name="culture">対象カルチャ</param>
        /// <returns>Color</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is string))
            {
                return(default(Color));
            }

            return(Converter.ConvertFrom(CultureInfo.CurrentCulture, value));
        }
        public void ExtendedColorTypeConverterParsesColors(string input)
        {
            ColorTypeConverter converter   = new ColorTypeConverter();
            object             convertFrom = converter.ConvertFrom(null, input, typeof(Color));

            if (convertFrom != null)
            {
                Color color = (Color)convertFrom;
                Assert.AreEqual(Color.Blue.ToArgb(), color.ToArgb());
            }
        }
        public void ReSet()
        {
            //InitializeComponent();
            Color color = (Color)colorTypeConv.ConvertFrom(colorName);

            Content = new Frame
            {
                OutlineColor = Color.Accent,
                Content      = new StackLayout
                {
                    //Orientation = HorizontalOptions.
                    Children =
                    {
                        new BoxView       {
                            Color        = color,
                            WidthRequest = 70, HeightRequest = 70
                        },
                        new StackLayout   {
                            Children =
                            {
                                new Label {
                                    Text            = colorName,
                                    FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                                    FontAttributes  = FontAttributes.Bold,
                                    VerticalOptions = LayoutOptions.CenterAndExpand,
                                    // HorizontalOptions = LayoutOptions.StartAndExpand
                                }, new Label{
                                    Text = String.Format("{0:X2}-{1:X2}-{2:X2}",
                                                         (int)(255 * color.R),
                                                         (int)(255 * color.G),
                                                         (int)(255 * color.B)),
                                    FontSize        = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                                    FontAttributes  = FontAttributes.Bold,
                                    VerticalOptions = LayoutOptions.CenterAndExpand,
                                    // HorizontalOptions = LayoutOptions.StartAndExpand
                                },
                            }
                        }
                    }
                }
            };

            Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);
        }