Click here to Skip to main content
15,894,646 members
Articles / Desktop Programming / WPF

Introduction to Composite WPF (CAL, Prism): Part 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (16 votes)
19 Jul 2009CPOL17 min read 72.9K   1.5K   53  
An article showing an extremely simple implementation of CompositeWPF.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Collections.Specialized;
using System.Xml;
using System.Windows.Documents;

namespace JamSoft.CALDemo.Modules.SettingsManager
{
    [Serializable]
    public class PropertiesCollection : IXmlSerializable
    {
        private NameValueCollection _properties = new NameValueCollection();
        private List<string> _keys = new List<string>();

        internal PropertiesCollection()
        {
        }

        public void SetSetting(string key, object value)
        {
            if (!_keys.Contains(key))
            {
                _properties.Add(key, value.ToString());
                _keys.Add(key);
            }
            else
            {
                _properties.Set(key, value.ToString());
            }
        }

        public object GetSettingValue(string key)
        {
            return _properties[key];
        }

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            _properties = new NameValueCollection();

            reader.Read();
            while (reader.MoveToNextAttribute())
            {
                _properties.Add(reader.Name, reader.Value);
            }

            _keys = _properties.AllKeys.ToList();
        }

        public void WriteXml(XmlWriter writer)
        {
            foreach (string key in _properties.Keys)
            {
                writer.WriteStartElement("property");
                string value = _properties[key];
                writer.WriteAttributeString(key, value);
                writer.WriteEndElement();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer JamSoft Solution Ltd
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions