Esempio n. 1
0
    public static Brush FreezeSolidBrush(string hex)
    {
        var _1 = HexToBrush.FromHex(hex);

        _1.Freeze();
        return(_1);
    }
        private static void OnTextStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var _0 = d as TextBlock;

            if (_0 != null)
            {
                var _1 = (string)e.NewValue;
                if (!_1.IsNullAndTrimAndEmpty())
                {
                    string _2  = _1.Trim().Replace(",", " ").Replace(",", " ");
                    var    _2s = _2.Split(' ');
                    foreach (var item in _2s)
                    {
                        //字号 字体颜色 fontweight 字体 背景色 xie(是否斜体)
                        if (_2s.Length >= 1 && _2s[0] != "?")
                        {
                            _0.FontSize = _2s[0].ToDouble();
                        }
                        if (_2s.Length >= 2 && _2s[1] != "?")
                        {
                            if (_2s[1].IndexOf("Ay") > -1)
                            {
                                _0.SetResourceReference(TextBlock.ForegroundProperty, _2s[1]);
                            }
                            else
                            {
                                TextBlock.SetForeground(_0, HexToBrush.FromHex(_2s[1]));
                            }
                        }
                        if (_2s.Length >= 3 && _2s[2] != "?")
                        {
                            _0.FontWeight = _2s[2].ToFontWeight();
                        }
                        if (_2s.Length >= 4 && _2s[3] != "?")
                        {
                            _0.FontFamily = new FontFamily(_2s[3]);
                        }
                        if (_2s.Length >= 5 && _2s[4] != "?")
                        {
                            if (_2s[4].IndexOf("Ay") > -1)
                            {
                                _0.SetResourceReference(TextBlock.BackgroundProperty, _2s[4]);
                            }
                            else
                            {
                                TextBlock.SetForeground(_0, HexToBrush.FromHex(_2s[4]));
                            }
                        }
                        if (_2s.Length >= 6 && _2s[5] != "?")
                        {
                            if (_2s[5] == "xie" || _2s[5].ToLower() == "true")
                            {
                                _0.FontStyle = FontStyles.Italic;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public object Clone()
        {
            AyLayerOptions _defaultAyLayerOptions = new AyLayerOptions();

            _defaultAyLayerOptions           = new AyLayerOptions();
            _defaultAyLayerOptions.CanDrag   = true;
            _defaultAyLayerOptions.HasShadow = false;
            _defaultAyLayerOptions.MaskBrush = HexToBrush.FromHex("#8C000000");
            return(_defaultAyLayerOptions);
        }
Esempio n. 4
0
    /// <summary>
    /// Create the image from the system's icons
    /// </summary>
    /// <param name="icon"></param>
    private void CreateImage(AyMessageBoxImage icon)
    {
        switch (icon)
        {
        case AyMessageBoxImage.None:
            ImagePlaceholder.Visibility = Visibility.Collapsed;
            break;

        case AyMessageBoxImage.Information:
            ImagePlaceholder.Icon       = "path_ay_msg_info";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#909399");
            break;

        case AyMessageBoxImage.Question:
            ImagePlaceholder.Icon       = "path_ay_msg_question";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#409EFF");
            break;

        case AyMessageBoxImage.Warning:
            ImagePlaceholder.Icon       = "path_ay_msg_warning";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#E6A23C");
            break;

        case AyMessageBoxImage.Error:
            ImagePlaceholder.Icon       = "path_ay_msg_error";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#F56C6C");
            break;

        case AyMessageBoxImage.Delete:
            ImagePlaceholder.Icon       = "path_ay_msg_delete";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#F56C6C");
            break;

        case AyMessageBoxImage.Right:
            ImagePlaceholder.Icon       = "path_ay_msg_right";
            ImagePlaceholder.Foreground = HexToBrush.FromHex("#67C473");

            break;

        default:
            throw new ArgumentOutOfRangeException("icon");
        }
    }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var _formatter = Formatter.ToObjectString();
            double _value = value.ToDouble();
            string[] arrayEndGroup = _formatter.Split('#');
            string GroupResult = null;
            string[] _subgroupArray = arrayEndGroup[0].Split(',');
            foreach (var SubGroup in _subgroupArray)
            {
                GroupResult = CompareSubGroup(SubGroup, _value);
                if (GroupResult == null)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }

            if (GroupResult == null)
            {
                if (arrayEndGroup.Length > 1)
                {
                    GroupResult = arrayEndGroup[1];
                }
                else
                {
                    return Binding.DoNothing;
                }

            }
            if (GroupResult == "None")
            {
                return DependencyProperty.UnsetValue;
            }
            return HexToBrush.FromHex("#"+GroupResult);

        }
Esempio n. 6
0
        public Viewbox GetMoreIcon()
        {
            var xc = (from c in PathIcon.Instance.xmlDoc.Descendants(Icon)
                      select c).FirstOrDefault();

            if (xc != null)
            {
                //拆分path
                string nv      = $"<ay>{xc.Value}</ay>";
                var    xd      = XDocument.Parse(nv);
                var    results = from c in xd.Descendants("path")
                                 select c;
                Viewbox vb           = new Viewbox();
                Binding bindingWidth = new Binding {
                    Path = new PropertyPath("Width"), Source = this, Mode = BindingMode.TwoWay, TargetNullValue = 16.00
                };
                vb.SetBinding(Viewbox.WidthProperty, bindingWidth);
                Binding bindingHeight = new Binding {
                    Path = new PropertyPath("Height"), Source = this, Mode = BindingMode.TwoWay, TargetNullValue = 16.00
                };
                vb.SetBinding(Viewbox.HeightProperty, bindingHeight);
                Grid g = new Grid();
                vb.Child = g;
                Brush defaultFil = null;

                var _hasbg = xc.Attribute("main");
                if (_hasbg != null && _hasbg.Value == "1")
                {
                    Foreground = null;
                }
                if (Foreground == null)
                {
                    var _hasFill = xc.Attribute("fil");
                    if (_hasFill != null && _hasFill.Value != "")
                    {
                        defaultFil = HexToBrush.FromHex(_hasFill.Value);
                    }

                    foreach (var result in results)
                    {
                        if (!string.IsNullOrEmpty(result.Attribute("d").Value))
                        {
                            Path p = new Path();
                            p.Data = PathGeometry.Parse(result.Attribute("d").Value);
                            if (defaultFil != null)
                            {
                                p.Fill = defaultFil;
                            }
                            else
                            {
                                var yanse = result.Attribute("fill");
                                if (yanse != null && yanse.Value != "")
                                {
                                    p.Fill = HexToBrush.FromHex(yanse.Value);
                                }
                                else
                                {
                                    var _hasEFill = xc.Attribute("efil");
                                    if (_hasEFill != null && _hasEFill.Value != "")
                                    {
                                        p.Fill = HexToBrush.FromHex(_hasEFill.Value);
                                    }
                                    else
                                    {
                                        if (EFil != null)
                                        {
                                            Binding bindingEfill = new Binding {
                                                Path = new PropertyPath("EFil"), Source = this, Mode = BindingMode.TwoWay
                                            };
                                            p.SetBinding(Path.FillProperty, bindingEfill);
                                        }
                                    }
                                }
                            }
                            g.Children.Add(p);
                        }
                    }
                }
                else
                {
                    foreach (var result in results)
                    {
                        if (!string.IsNullOrEmpty(result.Attribute("d").Value))
                        {
                            Path p = new Path();
                            p.Data = PathGeometry.Parse(result.Attribute("d").Value);
                            Binding bindingFill = new Binding {
                                Path = new PropertyPath("Foreground"), Source = this, Mode = BindingMode.TwoWay
                            };
                            p.SetBinding(Path.FillProperty, bindingFill);
                            Binding bindingStroke = new Binding {
                                Path = new PropertyPath("Stroke"), Source = this, Mode = BindingMode.TwoWay
                            };
                            p.SetBinding(Path.StrokeProperty, bindingStroke);

                            Binding bindingStrokeThickness = new Binding {
                                Path = new PropertyPath("StrokeThickness"), Source = this, Mode = BindingMode.TwoWay
                            };
                            p.SetBinding(Path.StrokeThicknessProperty, bindingStrokeThickness);

                            g.Children.Add(p);
                        }
                    }
                }
                Binding bindingStretch = new Binding {
                    Path = new PropertyPath("Stretch"), Source = this, Mode = BindingMode.TwoWay
                };
                vb.SetBinding(Viewbox.StretchProperty, bindingStretch);
                return(vb);
            }
            return(null);
        }
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     ((App)App.Current)._theme.AccentBrush = HexToBrush.FromHex("#D18023");
 }
        private void PrepareStyles(List <Type> typeList, Brush accentBrush, ResourceDictionary parent)
        {
            var         templateDirectory = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            string      absolutePath      = System.IO.Path.Combine(templateDirectory, "ay.Wpf.Theme.Element.ThemeConfig.Default.xml");
            XmlDocument doc = new XmlDocument();

            doc.Load(absolutePath);
            XmlNode     node   = doc.SelectSingleNode("Root");
            XmlNodeList childs = node.ChildNodes;

            foreach (Type type in typeList)
            {
                ElementStylesBase ElementStylesBase = Activator.CreateInstance(type, ColorMode) as ElementStylesBase;
                if (ElementStylesBase.MergedDatas.Count > 0)
                {
                    PrepareStyles(ElementStylesBase.MergedDatas, accentBrush, ElementStylesBase);
                }


                foreach (XmlNode ass in childs)
                {
                    var keyvaluedesc = ass.Attributes["Des"].Value;
                    if (keyvaluedesc == "自动计算")
                    {
                        continue;
                    }
                    var keyname  = ass.Name;
                    var keyvalue = ass.Attributes["value"].Value;

                    var _1 = HexToBrush.FromHex(keyvalue) as SolidColorBrush;
                    ElementStylesBase.EnsureResource(keyname, _1);
                    //添加color
                    ElementStylesBase.EnsureResource(keyname + ".color", _1.Color);
                    if (keyname == "colorprimary")
                    {
                        SetColor(ElementStylesBase, _1, "colorprimary");
                    }
                    else if (keyname == "colorsuccess")
                    {
                        SetColor(ElementStylesBase, _1, "colorsuccess");
                    }
                    else if (keyname == "colorwarning")
                    {
                        SetColor(ElementStylesBase, _1, "colorwarning");
                    }
                    else if (keyname == "colordanger")
                    {
                        SetColor(ElementStylesBase, _1, "colordanger");
                    }
                    else if (keyname == "colorinfo")
                    {
                        SetColor(ElementStylesBase, _1, "colorinfo");
                    }
                }

                ElementStylesBase.Initialize();
                if (parent != null)
                {
                    parent.MergedDictionaries.Add(ElementStylesBase);
                }
            }
        }