Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
Serialize/de-serialize appearances
posted

Hi,

I need to serialize to an xml file the properties changed in the appearances of some infragistics controls.

Could someone post some code to serialize an appearance object, thxs!!

Parents
No Data
Reply
  • 37774
    Verified Answer
    posted

    On some controls, such as the grid, there are SaveAsXml and LoadFromXml methods that will accomplish this for you.  For other controls, you would basically have to roll your own solution.  Since the Appearance objects implement ISerializable, you can do this with a SoapFormatter.  I just whipped up a quick example of saving just the Appearance property, but you could add as many entries as you want for the various dictionary keys:

     private void ultraButton1_Click(object sender, EventArgs e)
    {
        using (FileStream stream = new FileStream("Appearance.xml", FileMode.Create))
        {
            SoapFormatter formatter = new SoapFormatter();
            ObjectStreamer streamer = new ObjectStreamer();
            streamer.Dictionary.Add("Appearance", this.ultraButton1.Appearance);
            formatter.Serialize(stream, streamer);
        }
    }

    private void ultraButton2_Click(object sender, EventArgs e)
    {
        using (FileStream stream = new FileStream("Appearance.xml", FileMode.Open))
        {
            SoapFormatter formatter = new SoapFormatter();
            formatter.Binder = new Binder();
            ObjectStreamer streamer = formatter.Deserialize(stream) as ObjectStreamer;

            this.ultraButton2.Appearance = ((SerializationEntry)streamer.Dictionary["Appearance"]).Value as AppearanceBase;
        }
    }

    -Matt

Children
No Data