private void CreateDefaultAttributes()
        {
            MobiseConfiguration parent = this.Parent as MobiseConfiguration;

            if (parent != null)
            {
                foreach (AttributeCategoryModel category in parent.baseControlAttributes)
                {
                    AttributeCategoryModel newCategory = new AttributeCategoryModel(this);
                    newCategory.FromXml(category.ToXml());
                    this.AttributeCategories.Add(newCategory);
                }
            }
        }
        /// <summary>
        /// Froms the XML.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public override void FromXml(XElement xml)
        {
            this.Name = xml.Attribute("name") != null?xml.Attribute("name").Value : string.Empty;

            this.Description = xml.Attribute("description") != null?xml.Attribute("description").Value : string.Empty;

            this.IconUrl = xml.Attribute("iconUrl") != null?xml.Attribute("iconUrl").Value : string.Empty;

            this.ContainerType = xml.Attribute("ContainerType") != null?xml.Attribute("ContainerType").Value : string.Empty;

            this.ContainerPropertyTypes = xml.Attribute("ContainerPropertyTypes") != null?xml.Attribute("ContainerPropertyTypes").Value : string.Empty;

            this.ContainerProperty = xml.Attribute("ContainerProperty") != null?xml.Attribute("ContainerProperty").Value : string.Empty;

            this.Browsable = xml.Attribute("browsable") != null?bool.Parse(xml.Attribute("browsable").Value) : true;

            if (xml.Attribute("class") != null)
            {
                this.DefaultStyleClass = xml.Attribute("class").Value;
            }

            XElement designerAttributesElement = xml.Element("designerAttributes");

            if (designerAttributesElement != null && designerAttributesElement.HasElements)
            {
                foreach (XElement element in designerAttributesElement.Elements())
                {
                    string key = element.Attribute("name") != null?element.Attribute("name").Value.ToLowerInvariant() : string.Empty;

                    string value = element.Attribute("value") != null?element.Attribute("value").Value : string.Empty;

                    if (!string.IsNullOrEmpty(key))
                    {
                        this.DesignerAttributes[key] = value;
                    }
                }
            }

            if (this.DesignerAttributes.ContainsKey("portraitwidth") || this.DesignerAttributes.ContainsKey("portraitheight"))
            {
                double width = 100, height = 40;
                width  = this.DesignerAttributes.ContainsKey("portraitwidth") ? double.Parse(this.DesignerAttributes["portraitwidth"]) : 100;
                height = this.DesignerAttributes.ContainsKey("portraitheight") ? double.Parse(this.DesignerAttributes["portraitheight"]) : 40;
                this.AttributeCategories[1].ControlAttributes[0].DefaultValue = new Rect(0, 0, width, height);
                if (this.Name.Equals("screen", StringComparison.OrdinalIgnoreCase) || this.Name.Equals("view", StringComparison.OrdinalIgnoreCase))
                {
                    this.AttributeCategories[1].ControlAttributes[1].DefaultValue = new Rect(0, 0, height, width);
                }
                else
                {
                    this.AttributeCategories[1].ControlAttributes[1].DefaultValue = new Rect(0, 0, width, height);
                }
            }

            if (this.DesignerAttributes.ContainsKey("landscapewidth") || this.DesignerAttributes.ContainsKey("landscapeheight"))
            {
                double width = 100, height = 40;
                width  = this.DesignerAttributes.ContainsKey("landscapewidth") ? double.Parse(this.DesignerAttributes["landscapewidth"]) : 100;
                height = this.DesignerAttributes.ContainsKey("landscapeheight") ? double.Parse(this.DesignerAttributes["landscapeheight"]) : 40;
                this.AttributeCategories[1].ControlAttributes[1].DefaultValue = new Rect(0, 0, width, height);
            }

            XElement AttributeCategoriesElement = xml.Element("AttributeCategories");

            if (AttributeCategoriesElement != null && AttributeCategoriesElement.HasElements)
            {
                int numOfCategories = this.AttributeCategories.Count();
                foreach (XElement item in AttributeCategoriesElement.Elements())
                {
                    bool   created      = false;
                    string categoryName = item.Attribute("name") != null?item.Attribute("name").Value : string.Empty;

                    AttributeCategoryModel category = this.AttributeCategories.FirstOrDefault(c => c.Name == categoryName);
                    if (category == null)
                    {
                        created  = true;
                        category = new AttributeCategoryModel(this);
                        category.FromXml(item);
                        this.AttributeCategories.Add(category);
                    }
                    else
                    {
                        category.FromXml(item);
                    }
                }
            }

            XElement VisualStatesDefinitionsElement = xml.Element("VisualStates");

            if (VisualStatesDefinitionsElement != null && VisualStatesDefinitionsElement.HasElements)
            {
                foreach (XElement item in VisualStatesDefinitionsElement.Elements())
                {
                    string stateName = item.Attribute("name") != null?item.Attribute("name").Value : string.Empty;

                    VisualStateDefinitionModel visualState = this.VisualStates.FirstOrDefault(c => c.Name == stateName);
                    if (visualState == null)
                    {
                        visualState = new VisualStateDefinitionModel();
                        this.VisualStates.Add(visualState);
                    }
                    visualState.FromXml(item);
                }
            }
        }
Exemple #3
0
 public AttributeModel(AttributeCategoryModel parent)
     : base(parent)
 {
     this.Validations = new TrulyObservableCollection<ValidationModel>();
 }