Exemplo n.º 1
0
        public XmlElement Serialize(Block block, XmlDocument xmlDocument)
        {
            var paragraph        = (Paragraph)block;
            var paragraphElement = xmlDocument.CreateElement("Paragraph");

            foreach (var inline in paragraph.Inlines)
            {
                var properties = inline.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty)
                                 .Where(p => ParagraphSerializationHelper.PropertyConverters.Keys.Contains(p.Name))
                                 .Select(p => Tuple.Create(p.Name, p.GetValue(inline)));
                var inlineElement = xmlDocument.CreateElement("Inline");
                foreach (var prop in properties)
                {
                    var xmlAttribute = xmlDocument.CreateAttribute(prop.Item1);
                    if (prop.Item2 != null)
                    {
                        xmlAttribute.InnerText = prop.Item2.ToString(); //TODO сложные объекты?
                    }
                    inlineElement.Attributes.Append(xmlAttribute);
                }
                inlineElement.SetAttribute("StyleName", FlowDocumentHelper.GetStyleName(inline));

                paragraphElement.AppendChild(inlineElement);
            }
            return(paragraphElement);
        }
Exemplo n.º 2
0
        public void Upadate()
        {
            foreach (var style in TextStyles)
            {
                style.IsActive = false;
            }
            var inline = _documentState.CurrentSelection.Start.Parent as Inline;

            if (inline == null)
            {
                return;
            }
            var styleName = FlowDocumentHelper.GetStyleName(inline);

            if (String.IsNullOrEmpty(styleName))
            {
                return;
            }
            var textStyle = TextStyles.SingleOrDefault(s => s.TextStyle.Name == styleName);

            if (textStyle == null)
            {
                return;
            }

            textStyle.IsActive = true;
        }
Exemplo n.º 3
0
 private void ChangeStyle(ITextStyle style)
 {
     foreach (var block in _flowDocument.Blocks)
     {
         var paragraph = block as Paragraph;
         if (paragraph == null)
         {
             continue;
         }
         foreach (var inline in paragraph.Inlines)
         {
             if (FlowDocumentHelper.GetStyleName(inline) == style.Name)
             {
                 inline.ApplyTextStyle(style);
             }
         }
     }
 }