protected bool SaveStyleColorToXml(StyleColor styleColor, XmlDocument xmlDoc, XmlElement parentElement) { XmlElement propertyElement = xmlDoc.CreateElement("Color"); parentElement.AppendChild(propertyElement); SaveStringToChildElement("FillType", styleColor.FillType.ToString(), xmlDoc, propertyElement); SaveStringToChildElement("ARGB", styleColor.ARGB.ToString(), xmlDoc, propertyElement); SaveStringToChildElement("Angle", styleColor.Angle.ToString(), xmlDoc, propertyElement); if (styleColor.Frames != null) { XmlElement framesElement = xmlDoc.CreateElement("Frames"); propertyElement.AppendChild(framesElement); // Copy the collection in case the original collection is modifying at this time. Dictionary <double, int> copyFrames = new Dictionary <double, int>(styleColor.Frames); foreach (KeyValuePair <double, int> frame in copyFrames) { XmlElement frameElement = xmlDoc.CreateElement("Frame"); framesElement.AppendChild(frameElement); SaveStringToChildElement("Key", frame.Key.ToString(), xmlDoc, frameElement); SaveStringToChildElement("Value", frame.Value.ToString(), xmlDoc, frameElement); } } return(true); }
internal override void LoadDataFromXml(XmlElement element) { CheckTagName(element); // Style only create string or color properties, if you want they to be specific type properties, override this method. XmlElement propertiesElement = element["StyleProperties"]; if (propertiesElement != null && propertiesElement.ChildNodes.Count > 0) { foreach (XmlElement propertyElement in propertiesElement.ChildNodes) { XmlElement colorElement = propertyElement["Color"]; if (colorElement != null) { StyleColor color = new StyleColor(); if (LoadStyleColorFromXml(colorElement, ref color)) { SetStyleProperty(propertyElement.Name, color); } } else { string value = null; if (LoadStringFromChildElementInnerText("Value", propertyElement, ref value)) { SetStyleProperty(propertyElement.Name, value); } } } } }
public IStyleProperty SetStyleProperty(string name, StyleColor color) { if (String.IsNullOrEmpty(name)) { return(null); } StyleColorProperty property = null; if (Contains(name)) { property = _styleProperties[name] as StyleColorProperty; if (property != null && !property.ColorValue.Equals(color)) { property.ColorValue = new StyleColor(color); } } if (property == null) { property = new StyleColorProperty(name, color); _styleProperties[name] = property; } return(property); }
public StyleColor(StyleColor other) { FillType = other.FillType; ARGB = other.ARGB; Angle = other.Angle; Frames = new Dictionary <double, int>(other.Frames); }
protected bool LoadStyleColorFromXml(XmlElement colorElement, ref StyleColor styleColor) { if (colorElement != null) { LoadEnumFromChildElementInnerText <ColorFillType>("FillType", colorElement, ref styleColor.FillType); LoadIntFromChildElementInnerText("ARGB", colorElement, ref styleColor.ARGB); LoadDoubleFromChildElementInnerText("Angle", colorElement, ref styleColor.Angle); if (styleColor.Frames == null) { styleColor.Frames = new Dictionary <double, int>(); } XmlElement framesElement = colorElement["Frames"]; if (framesElement != null) { XmlNodeList childList = framesElement.ChildNodes; if (childList != null || childList.Count > 0) { foreach (XmlElement childElement in childList) { try { XmlElement keyElement = childElement["Key"]; XmlElement valueElement = childElement["Value"]; if (keyElement != null && valueElement != null) { styleColor.Frames[Double.Parse(keyElement.InnerText)] = Int32.Parse(valueElement.InnerText); } } catch { continue; } } } } } return(true); }
protected bool LoadStyleColorProperty(XmlElement parentElement, string propertyName) { XmlElement propertyElement = parentElement[propertyName]; if (propertyElement != null) { XmlElement colorElement = propertyElement["Color"]; if (colorElement != null) { StyleColor color = new StyleColor(); if (LoadStyleColorFromXml(colorElement, ref color)) { SetStyleProperty(propertyElement.Name, color); return(true); } } } return(false); }
public StyleColorProperty(string name, StyleColor color) : base(name) { _color = new StyleColor(color); }
//public StyleColor(string colorString) //{ // // TODO : Convert string to StyleColor //} public StyleColor Clone() { StyleColor newColor = new StyleColor(this); return(newColor); }
internal static void GetStyleValueFromRichText(string richText, Style style) { if (String.IsNullOrEmpty(richText) || style == null) { return; } try { //Object obj = System.Windows.Markup.XamlReader.Load(richText); Object obj = System.Windows.Markup.XamlReader.Parse(richText); if (obj != null) { TextElement line = null; if (obj is Section) { Section section = obj as Section; if (section.Blocks.Count > 0) { Block block = section.Blocks.FirstBlock; if (block is Paragraph) { Paragraph para = block as Paragraph; if (para.Inlines.Count > 0) { line = para.Inlines.FirstInline; } } } } else if (obj is Span) { Span span = obj as Span; if (span.Inlines.Count > 0) { line = span.Inlines.FirstInline; } } if (line != null) { // TextElement line = para.Inlines.FirstInline; if (line is Run) { Run run = line as Run; if (run.FontWeight == FontWeights.Bold) { style.SetStyleProperty(StylePropertyNames.BOLD_PROP, true); } else { style.SetStyleProperty(StylePropertyNames.BOLD_PROP, false); } if (run.FontStyle == FontStyles.Italic) { style.SetStyleProperty(StylePropertyNames.ITALIC_PROP, true); } else { style.SetStyleProperty(StylePropertyNames.ITALIC_PROP, false); } style.SetStyleProperty(StylePropertyNames.UNDERLINE_PROP, false); style.SetStyleProperty(StylePropertyNames.STRIKETHROUGH_PROP, false); foreach (TextDecoration dec in run.TextDecorations) { if (dec.Location == TextDecorationLocation.Underline) { style.SetStyleProperty(StylePropertyNames.UNDERLINE_PROP, true); } else if (dec.Location == TextDecorationLocation.Strikethrough) { style.SetStyleProperty(StylePropertyNames.STRIKETHROUGH_PROP, true); } } style.SetStyleProperty(StylePropertyNames.FONT_SIZE_PROP, run.FontSize); style.SetStyleProperty(StylePropertyNames.FONT_FAMILY_PROP, run.FontFamily.ToString()); Color tColor = ((SolidColorBrush)run.Foreground).Color; StyleColor stylecolor = new StyleColor(ColorFillType.Solid, ((tColor.A << 24) | (tColor.R << 16) | (tColor.G << 8) | tColor.B)); style.SetStyleProperty(StylePropertyNames.FONT_COLOR_PROP, stylecolor); // return;//only need first line style } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public virtual StyleColor GetStyleColorValue(StyleColor defaultValue) { // TODO : Convert string to StyleColor return(defaultValue); }