示例#1
0
        // Load hierarchical data from XML to display and edit in the PropertyGridView
        private void LoadSUVDataFromXML()
        {
            Uri uri = new Uri("/CoolSUVs.xml", UriKind.Relative);
            StreamResourceInfo info = Application.GetResourceStream(uri);

            var xmlDoc = XDocument.Load(info.Stream);// loads suv xml data using Linq to XML API
            // read SUV data
            m_suvs = new List<Suv>();
            foreach (var suvElem in xmlDoc.Descendants("suv"))
            {
                var suv = new Suv
                {
                    Name = (string)suvElem.Attribute("name"),
                    Awd = (bool) suvElem.Attribute("awd"),
                    Price = (float)suvElem.Attribute("msrp"),
                    Min = (float)suvElem.Attribute("min"),
                    Max = (float)suvElem.Attribute("max"),
                };

                string[] configStrings = { "Standard", "Plus", "Limited"};
                foreach (string configString in configStrings)
                {
                    Suv.Configurations config;
                    if (Enum.TryParse(configString, true, out config))
                        suv.Config = config;
                }

                int color;
                if (int.TryParse((string) suvElem.Attribute("color"), out color))
                    suv.Color = Color.FromArgb(color);
                else
                    suv.Color = Color.FromName((string) suvElem.Attribute("color"));
                m_suvs.Add(suv);
            }
        }
示例#2
0
        // Load hierarchical data from XML to display and edit in the PropertyGridView
        private void LoadSUVDataFromXML()
        {
            Uri uri = new Uri("/CoolSUVs.xml", UriKind.Relative);
            StreamResourceInfo info = Application.GetResourceStream(uri);

            var xmlDoc = XDocument.Load(info.Stream);// loads suv xml data using Linq to XML API

            // read SUV data
            m_suvs = new List <Suv>();
            foreach (var suvElem in xmlDoc.Descendants("suv"))
            {
                var suv = new Suv
                {
                    Name  = (string)suvElem.Attribute("name"),
                    Awd   = (bool)suvElem.Attribute("awd"),
                    Price = (float)suvElem.Attribute("msrp"),
                    Min   = (float)suvElem.Attribute("min"),
                    Max   = (float)suvElem.Attribute("max"),
                };

                string[] configStrings = { "Standard", "Plus", "Limited" };
                foreach (string configString in configStrings)
                {
                    Suv.Configurations config;
                    if (Enum.TryParse(configString, true, out config))
                    {
                        suv.Config = config;
                    }
                }

                int color;
                if (int.TryParse((string)suvElem.Attribute("color"), out color))
                {
                    suv.Color = Color.FromArgb(color);
                }
                else
                {
                    suv.Color = Color.FromName((string)suvElem.Attribute("color"));
                }
                m_suvs.Add(suv);
            }
        }