示例#1
0
 public static void ApplyTextStyle(this TextSelection selection, ITextStyle style)
 {
     if (selection == null || selection.Start == selection.End)
     {
         return;
     }
     selection.ApplyPropertyValue(TextElement.FontFamilyProperty, style.FontFamily);
     selection.ApplyPropertyValue(TextElement.FontSizeProperty, style.FontSize * 96d / 72d);
     selection.ApplyPropertyValue(TextElement.FontStyleProperty, style.FontStyle);
     selection.ApplyPropertyValue(TextElement.FontWeightProperty, style.FontWeight);
     selection.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(style.FontColor));
     FlowDocumentHelper.SetStyleName(selection.Start.Parent, style.Name);
 }
        public void Deserialize(XmlNode xmlNode, FlowDocument flowDocument)
        {
            var paragraph = new Paragraph();

            foreach (XmlNode inline in xmlNode.ChildNodes)
            {
                var run = new Run(); //TODO: other inlines ?
                foreach (XmlAttribute attribute in inline.Attributes)
                {
                    if (attribute.Name != "StyleName")
                    {
                        run.GetType().GetProperty(attribute.Name).SetValue(run, ParagraphSerializationHelper.PropertyConverters[attribute.Name].ConvertFromString(attribute.InnerText));
                    }
                }
                if (xmlNode.Attributes["StyleName"] != null)
                {
                    FlowDocumentHelper.SetStyleName(run, xmlNode.Attributes["StyleName"].InnerText);
                }
                paragraph.Inlines.Add(run);
            }
            flowDocument.Blocks.Add(paragraph);
        }
        public void Deserialize(XmlNode xmlNode, FlowDocument flowDocument)
        {
            var list = new List {
                MarkerStyle = _markerStyle
            };

            foreach (XmlNode listItemNode in xmlNode.ChildNodes)
            {
                var listItem = new ListItem();
                foreach (XmlNode listItemBlockNode in listItemNode.ChildNodes)
                {
                    var paragraph = new Paragraph();

                    foreach (XmlNode listItemInlineNode in listItemBlockNode.ChildNodes)
                    {
                        var run = new Run();
                        foreach (XmlAttribute attribute in listItemInlineNode.Attributes)
                        {
                            if (attribute.Name != "StyleName")
                            {
                                run.GetType().GetProperty(attribute.Name).SetValue(run,
                                                                                   ParagraphSerializationHelper.PropertyConverters[attribute.Name].ConvertFromString(
                                                                                       attribute.InnerText));
                            }
                        }
                        if (xmlNode.Attributes["StyleName"] != null)
                        {
                            FlowDocumentHelper.SetStyleName(run, xmlNode.Attributes["StyleName"].InnerText);
                        }
                        paragraph.Inlines.Add(run);
                    }
                    listItem.Blocks.Add(paragraph);
                }
                list.ListItems.Add(listItem);
            }
            flowDocument.Blocks.Add(list);
        }