C # Custom class of custom settings not saved

I have the following class:

[Serializable]
[XmlRoot ( ElementName = "TextData", IsNullable = false)]
public class TextData
{
    private System.Drawing.Font fontColor;

    [XmlAttribute ( AttributeName = "Font" )]
    public System.Drawing.Font Font { get; set; }

    [XmlAttribute ( AttributeName = "FontColor" )]
    public System.Drawing.Color FontColor { get; set; }

    [XmlAttribute ( AttributeName = "Text" )]
    public string Text { get; set; }

    public TextData ( )
    {
    } // End of TextData
} // End of TextData

And I am trying to save it with the following code:

    // Create our font dialog
    FontDialog fontDialog = new FontDialog ( );
    fontDialog.ShowColor = true;

    // Display the dialog and check for an ok
    if ( DialogResult.OK == fontDialog.ShowDialog ( ) )
    {
        // Save our changes for the font settings
        if ( null == Properties.Settings.Default.MainHeadlineTextData )
        {
            Properties.Settings.Default.MainHeadlineTextData = new TextData ( );
        }
        Properties.Settings.Default.MainHeadlineTextData.Font = fontDialog.Font;
        Properties.Settings.Default.MainHeadlineTextData.FontColor = fontDialog.Color;
        Properties.Settings.Default.Save ( );
    }

Every time I download the application, the Properties.Settings.Default.MainHeadlineTextData property remains zero. Conservation does not seem to take effect. I read in another post that the class should be publicly available, and that is so. Any ideas why this will not work properly?

+5
source share
3 answers

, XML-. , Font , .Save() .

, SettingsBase ( ) - . Settings.Designer.cs) , .

.

. Settings.Designer.cs [SettingsSerializeAs (SettingsSerializeAs.Binary)] .MainHeadlineTextData​​strong > .

+10

, TypeConverter, XMLSerializable.

TypeConverter , Color Font XMLSerialiable.

: http://msdn.microsoft.com/en-us/library/ayybcxe5%28VS.80%29.aspx

+2
  • , , , - , , .
  • , ?
  • TextData, ?
+1

All Articles