Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to save Font's porperties to xml and read from XML file? (Read 1354 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to save Font's porperties to xml and read from XML file?
Jan 5th, 2015 at 3:27am
Print Post  
hi,
I override the methods that SaveToXml and LoadFromXml but I find that error always occurs when Save the FontStretch and the FontWeight perporty in debug. could you please give me some help? thanks.
Code
Select All
  protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
         {
	     base.SaveToXml(xmlElement, context);

             context.WriteObject((object)FontWeight, "FontWeight", xmlElement);
	     context.WriteObject((object)FontStretch, "FontStretch", xmlElement);

             context.WriteEnum(FlowDirection, "FlowDirection", xmlElement);
             context.WriteFontFamily(FontFamily, "FontFamily", xmlElement);
             context.WriteDouble(FontSize, "FontSize", xmlElement);
             context.WriteFontStyle(FontStyle, "FontStyle", xmlElement);
             context.WriteBrush(FontBrush, "FontBrush", xmlElement);
             context.WriteBrush(Brush, "Brush", xmlElement);
             context.WriteEnum(TextAlignment, "TextAlignment", xmlElement);
             context.WriteEnum(TextVerticalAlignment, "TextVerticalAlignment", xmlElement);
         }

         protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
         {
             base.LoadFromXml(xmlElement, context);
             FlowDirection = (FlowDirection) context.ReadEnum("FlowDirection", xmlElement);
             FontFamily = context.ReadFontFamily("FontFamily", xmlElement);
             FontSize = context.ReadDouble("FontSize", xmlElement);
             FontStretch = (FontStretch) context.ReadObject("FontStretch", xmlElement);
             FontStyle=   (FontStyle)context.ReadFontStyle("FontStyle", xmlElement);
             FontWeight = (FontWeight)context.ReadObject("FontWeight", xmlElement);
             FontBrush=   context.ReadBrush("FontBrush", xmlElement);
             Brush = context.ReadBrush("Brush", xmlElement);
             TextAlignment = (TextAlignment)context.ReadEnum("TextAlignment", xmlElement);
             TextVerticalAlignment = (AlignmentY)context.ReadEnum("TextVerticalAlignment", xmlElement);
         } 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to save Font's porperties to xml and read from XML file?
Reply #1 - Jan 5th, 2015 at 2:44pm
Print Post  
Hi,

Font attributes are saved by base DiagramItem class, you shouldn't have to save them yourself. WriteObject will work only for serializable types, and DiagramItem uses WPF's converters to get a string value and pass it to WriteString:

Code
Select All
object fontWeightValue = ReadLocalValue(FontWeightProperty);
if (fontWeightValue != DependencyProperty.UnsetValue)
{
	string stringVal = new FontWeightConverter().ConvertToString(fontWeightValue);
	context.WriteString(stringVal, "FontWeight", xmlElement);
}

object fontStretchValue = ReadLocalValue(FontStretchProperty);
if (fontStretchValue != DependencyProperty.UnsetValue)
{
	string stringVal = new FontStretchConverter().ConvertToString(fontStretchValue);
	context.WriteString(stringVal, "FontStretch", xmlElement);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint