예제 #1
0
        /// <summary>
        /// Finds the specified property, or creates it if it doesn't exist.
        /// </summary>
        public XamlProperty FindOrCreateAttachedProperty(Type ownerType, string propertyName)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            foreach (XamlProperty p in properties)
            {
                if (p.IsAttached && p.PropertyTargetType == ownerType && p.PropertyName == propertyName)
                {
                    return(p);
                }
            }
            XamlPropertyInfo info = XamlParser.TryFindAttachedProperty(ownerType, propertyName);

            if (info == null)
            {
                throw new ArgumentException("The attached property '" + propertyName + "' doesn't exist on " + ownerType.FullName, "propertyName");
            }
            XamlProperty newProperty = new XamlProperty(this, info);

            properties.Add(newProperty);
            return(newProperty);
        }
예제 #2
0
        internal static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute, bool real)
        {
            XamlPropertyInfo  propertyInfo = GetPropertyInfo(obj.Instance, obj.ElementType, attribute, obj.OwnerDocument.TypeFinder);
            XamlPropertyValue value        = null;

            var valueText = attribute.Value;

            if (valueText.StartsWith("{", StringComparison.Ordinal) && !valueText.StartsWith("{}", StringComparison.Ordinal))
            {
                var xamlObject = MarkupExtensionParser.Parse(valueText, obj, real ? attribute : null);
                value = xamlObject;
            }
            else
            {
                if (real)
                {
                    value = new XamlTextValue(obj.OwnerDocument, attribute);
                }
                else
                {
                    value = new XamlTextValue(obj.OwnerDocument, valueText);
                }
            }

            var property = new XamlProperty(obj, propertyInfo, value);

            obj.AddProperty(property);
        }
예제 #3
0
        /// <summary>
        /// Create a XamlPropertyValue for the specified value instance.
        /// </summary>
        public XamlPropertyValue CreatePropertyValue(object instance, XamlProperty forProperty)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            Type          elementType = instance.GetType();
            TypeConverter c           = TypeDescriptor.GetConverter(instance);
            var           ctx         = new DummyTypeDescriptorContext(this.ServiceProvider);

            ctx.Instance = instance;
            bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string));

            if (forProperty != null && hasStringConverter)
            {
                return(new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance)));
            }

            string ns     = GetNamespaceFor(elementType);
            string prefix = GetPrefixForNamespace(ns);

            XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);

            if (hasStringConverter &&
                XamlObject.GetContentPropertyName(elementType) != null)
            {
                xml.InnerText = c.ConvertToInvariantString(instance);
            }

            return(new XamlObject(this, xml, elementType, instance));
        }
예제 #4
0
        /// <summary>
        /// Create a XamlPropertyValue for the specified value instance.
        /// </summary>
        public XamlPropertyValue CreatePropertyValue(object instance, XamlProperty forProperty)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            Type          elementType = instance.GetType();
            TypeConverter c           = TypeDescriptor.GetConverter(instance);
            var           ctx         = new DummyTypeDescriptorContext(this.ServiceProvider);

            ctx.Instance = instance;
            bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string));

            if (forProperty != null && hasStringConverter)
            {
                return(new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance)));
            }

            string ns     = GetNamespaceFor(elementType);
            string prefix = GetPrefixForNamespace(ns);

            XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);

            if (hasStringConverter && XamlObject.GetContentPropertyName(elementType) != null)
            {
                xml.InnerText = c.ConvertToInvariantString(instance);
            }
            else if (instance is Brush && forProperty != null)                  // TODO: this is a hacky fix, because Brush Editor doesn't
            // edit Design Items and so we have no XML, only the Brush
            // object and we need to parse the Brush to XAML!
            {
                var s = new MemoryStream();
                XamlWriter.Save(instance, s);
                s.Seek(0, SeekOrigin.Begin);
                XmlDocument doc = new XmlDocument();
                doc.Load(s);
                xml = (XmlElement)_xmlDoc.ImportNode(doc.DocumentElement, true);

                var attLst = xml.Attributes.Cast <XmlAttribute>().ToList();
                foreach (XmlAttribute att in attLst)
                {
                    if (att.Name.StartsWith(XamlConstants.Xmlns))
                    {
                        var rootAtt = doc.DocumentElement.GetAttributeNode(att.Name);
                        if (rootAtt != null && rootAtt.Value == att.Value)
                        {
                            xml.Attributes.Remove(att);
                        }
                    }
                }
            }
            else if (instance is string)
            {
                xml.InnerText = (string)instance;
            }

            return(new XamlObject(this, xml, elementType, instance));
        }
예제 #5
0
 internal override void AddNodeTo(XamlProperty property)
 {
     if (!UpdateXmlAttribute(true))
     {
         property.AddChildNodeToProperty(element);
     }
     UpdateMarkupExtensionChain();
 }
예제 #6
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            bool         isDefaultValueSet         = false;
            object       defaultPropertyValue      = null;
            XamlProperty defaultCollectionProperty = null;

            if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
                obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
            }

            foreach (XmlNode childNode in GetNormalizedChildNodes(element))
            {
                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (defaultProperty != null && defaultProperty.IsCollection)
                    {
                        defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
                        CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
                    }
                    else
                    {
                        if (defaultProperty == null)
                        {
                            throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                        }

                        if (isDefaultValueSet)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }

                        obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
                        isDefaultValueSet = true;
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Finds the specified property, or creates it if it doesn't exist.
        /// </summary>
        public XamlProperty FindOrCreateProperty(string propertyName)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

//			if (propertyName == ContentPropertyName)
//				return

            foreach (XamlProperty p in properties)
            {
                if (!p.IsAttached && p.PropertyName == propertyName)
                {
                    return(p);
                }
            }
            PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(instance);
            PropertyDescriptor           propertyInfo        = propertyDescriptors[propertyName];
            XamlProperty newProperty;

            if (propertyInfo == null)
            {
                propertyDescriptors = TypeDescriptor.GetProperties(this.elementType);
                propertyInfo        = propertyDescriptors[propertyName];
            }

            if (propertyInfo != null)
            {
                newProperty = new XamlProperty(this, new XamlNormalPropertyInfo(propertyInfo));
            }
            else
            {
                EventDescriptorCollection events    = TypeDescriptor.GetEvents(instance);
                EventDescriptor           eventInfo = events[propertyName];

                if (eventInfo == null)
                {
                    events    = TypeDescriptor.GetEvents(this.elementType);
                    eventInfo = events[propertyName];
                }

                if (eventInfo != null)
                {
                    newProperty = new XamlProperty(this, new XamlEventPropertyInfo(eventInfo));
                }
                else
                {
                    throw new ArgumentException("The property '" + propertyName + "' doesn't exist on " + elementType.FullName, "propertyName");
                }
            }
            properties.Add(newProperty);
            return(newProperty);
        }
예제 #8
0
		/// <summary>For use by XamlParser only.</summary>
		internal void AddProperty(XamlProperty property)
		{
			#if DEBUG
			if (property.IsAttached == false) {
				foreach (XamlProperty p in properties) {
					if (p.IsAttached == false && p.PropertyName == property.PropertyName)
						throw new XamlLoadException("duplicate property:" + property.PropertyName);
				}
			}
			#endif
			properties.Add(property);
		}
예제 #9
0
		/// <summary>For use by XamlParser only.</summary>
		internal void AddProperty(XamlProperty property)
		{
			#if DEBUG
			if (property.IsAttached == false) {
				foreach (XamlProperty p in properties) {
					if (p.IsAttached == false && p.PropertyName == property.PropertyName)
						Debug.Fail("duplicate property");
				}
			}
			#endif
			properties.Add(property);
		}
예제 #10
0
        internal string GetPrefixForNamespace(string @namespace)
        {
            if (@namespace == XamlConstants.PresentationNamespace)
            {
                return(null);
            }

            string prefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(@namespace);

            if (_xmlDoc.DocumentElement.NamespaceURI == @namespace && _xmlDoc.Prefix == String.Empty)
            {
                return(string.Empty);
            }

            if (String.IsNullOrEmpty(prefix))
            {
                prefix = _typeFinder.GetPrefixForXmlNamespace(@namespace);

                string existingNamespaceForPrefix = null;
                if (!String.IsNullOrEmpty(prefix))
                {
                    existingNamespaceForPrefix = _xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix);
                }

                if (String.IsNullOrEmpty(prefix) ||
                    !String.IsNullOrEmpty(existingNamespaceForPrefix) &&
                    existingNamespaceForPrefix != @namespace)
                {
                    do
                    {
                        prefix = "Controls" + namespacePrefixCounter++;
                    } while (!String.IsNullOrEmpty(_xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix)));
                }

                string xmlnsPrefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(XamlConstants.XmlnsNamespace);
                System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(xmlnsPrefix));

                _xmlDoc.DocumentElement.SetAttribute(xmlnsPrefix + ":" + prefix, @namespace);

                if (@namespace == XamlConstants.DesignTimeNamespace)
                {
                    var ignorableProp = new XamlProperty(this._rootElement, new XamlDependencyPropertyInfo(MarkupCompatibilityProperties.IgnorableProperty, true));
                    ignorableProp.SetAttribute(prefix);
                }
            }

            return(prefix);
        }
예제 #11
0
 /// <summary>For use by XamlParser only.</summary>
 internal void AddProperty(XamlProperty property)
 {
                 #if DEBUG
     if (property.IsAttached == false)
     {
         foreach (XamlProperty p in properties)
         {
             if (p.IsAttached == false && p.PropertyName == property.PropertyName)
             {
                 Debug.Fail("duplicate property");
             }
         }
     }
                 #endif
     properties.Add(property);
 }
예제 #12
0
 /// <summary>For use by XamlParser only.</summary>
 internal void AddProperty(XamlProperty property)
 {
                 #if DEBUG
     if (property.IsAttached == false)
     {
         foreach (XamlProperty p in properties)
         {
             if (p.IsAttached == false && p.PropertyName == property.PropertyName)
             {
                 throw new XamlLoadException("duplicate property:" + property.PropertyName);
             }
         }
     }
                 #endif
     properties.Add(property);
 }
예제 #13
0
        //TODO: reseting path property for binding doesn't work in XamlProperty
        //use CanResetValue()
        internal void OnPropertyChanged(XamlProperty property)
        {
            XamlObject holder;

            if (!UpdateXmlAttribute(false, out holder))
            {
                if (holder != null &&
                    holder.XmlAttribute != null)
                {
                    holder.XmlAttribute.OwnerElement.RemoveAttributeNode(holder.XmlAttribute);
                    holder.xmlAttribute = null;
                    holder.ParentProperty.AddChildNodeToProperty(holder.element);

                    bool isThisUpdated = false;
                    foreach (XamlObject propXamlObject in holder.Properties.Where((prop) => prop.IsSet).Select((prop) => prop.PropertyValue).OfType <XamlObject>())
                    {
                        XamlObject innerHolder;
                        bool       updateResult = propXamlObject.UpdateXmlAttribute(true, out innerHolder);
                        Debug.Assert(updateResult || innerHolder == null);

                        if (propXamlObject == this)
                        {
                            isThisUpdated = true;
                        }
                    }
                    if (!isThisUpdated)
                    {
                        this.UpdateXmlAttribute(true, out holder);
                    }
                }
            }
            UpdateMarkupExtensionChain();

            if (!element.HasChildNodes && !element.IsEmpty)
            {
                element.IsEmpty = true;
            }

            if (property == NameProperty)
            {
                if (NameChanged != null)
                {
                    NameChanged(this, EventArgs.Empty);
                }
            }
        }
예제 #14
0
 internal override void AddNodeTo(XamlProperty property)
 {
     if (attribute != null)
     {
         property.ParentObject.XmlElement.Attributes.Append(attribute);
     }
     else if (textValue != null)
     {
         attribute = property.SetAttribute(textValue);
         textValue = null;
     }
     else if (cDataSection != null)
     {
         property.AddChildNodeToProperty(cDataSection);
     }
     else
     {
         property.AddChildNodeToProperty(textNode);
     }
 }
예제 #15
0
 internal abstract void AddNodeTo(XamlProperty property);
예제 #16
0
 //TODO: reseting path property for binding doesn't work in XamlProperty
 //use CanResetValue()
 internal void OnPropertyChanged(XamlProperty property)
 {
     UpdateXmlAttribute(false);
     UpdateMarkupExtensionChain();
 }
예제 #17
0
		/// <summary>
		/// Finds the specified property, or creates it if it doesn't exist.
		/// </summary>
		public XamlProperty FindOrCreateAttachedProperty(Type ownerType, string propertyName)
		{
			if (ownerType == null)
				throw new ArgumentNullException("ownerType");
			if (propertyName == null)
				throw new ArgumentNullException("propertyName");
			
			foreach (XamlProperty p in properties) {
				if (p.IsAttached && p.PropertyTargetType == ownerType && p.PropertyName == propertyName)
					return p;
			}
			XamlPropertyInfo info = XamlParser.TryFindAttachedProperty(ownerType, propertyName);
			if (info == null) {
				throw new ArgumentException("The attached property '" + propertyName + "' doesn't exist on " + ownerType.FullName, "propertyName");
			}
			XamlProperty newProperty = new XamlProperty(this, info);
			properties.Add(newProperty);
			return newProperty;
		}
예제 #18
0
 private static void ParseProperty(XamlProperty property, IHtmlDocument htmlDocument, IHtmlElement element)
 {
     if (property.IsCollection)
     {
         foreach (var prp in property.CollectionElements)
         {
             if (prp is XamlObject)
             {
                 if (((XamlObject)prp).Instance is FrameworkElement)
                 {
                     ParseObject((XamlObject)prp, htmlDocument, element);
                 }
             }
         }
     }
     else
     {
         if (!string.IsNullOrEmpty(property.ParentObject.ContentPropertyName) && property.PropertyName == property.ParentObject.ContentPropertyName)
         {
             ParseObject(property.PropertyValue, htmlDocument, element);
         }
         else
         {
             switch (property.PropertyName)
             {
                 case "Row":
                     {
                         var rw = Convert.ToInt32(property.ValueOnInstance);
                         //element.Style.SetProperty("grid-row", (rw + 1).ToString());
                         return;
                     }
                 case "RowSpan":
                     {
                         //element.Style.SetProperty("grid-row-span", property.ValueOnInstance.ToString());
                         return;
                     }
                 case "Column":
                     {
                         var rw = Convert.ToInt32(property.ValueOnInstance);
                         //element.Style.SetProperty("grid-column", (rw + 1).ToString());
                         return;
                     }
                 case "ColumnSpan":
                     {
                         //element.Style.SetProperty("grid-column-span", property.ValueOnInstance.ToString());
                         return;
                     }
                 case "Orientation":
                     {
                         element.Style.FlexDirection = property.ValueOnInstance.ToString() == "Vertical" ? "Row" : "Column";
                         return;
                     }
                 case "Text":
                     {
                         //When ctrl is a TextBox / TranslateTextBlock
                         element.TextContent = (property.ValueOnInstance ?? "").ToString();
                         return;
                     }
                 case "Stroke":
                     {
                         //When ctrl is a Rectangle
                         element.Style.BorderColor = ParseXamlColor(property.ValueOnInstance);
                         element.Style.BorderStyle = "solid";
                         return;
                     }
                 case "StrokeThickness":
                     {
                         //When ctrl is a Rectangle
                         element.Style.BorderWidth = property.ValueOnInstance.ToString() + "px";
                         element.Style.BorderStyle = "solid";
                         return;
                     }
                 case "Width":
                     {
                         element.Style.Width = property.ValueOnInstance.ToString() + "px";
                         return;
                     }
                 case "Height":
                     {
                         element.Style.Height = property.ValueOnInstance.ToString() + "px";
                         return;
                     }
                 case "Background":
                 case "Fill":
                     {
                         element.Style.Background = ParseXamlColor(property.ValueOnInstance);
                         return;
                     }
                 case "Margin":
                     {
                         element.Style.Left = ((Thickness)property.ValueOnInstance).Left.ToString() + "px";
                         element.Style.Top = ((Thickness)property.ValueOnInstance).Top.ToString() + "px";
                         return;
                     }
                 case "Left":
                     {
                         //if (property.ParentObject.ParentObject.Instance is Canvas)
                         //element.Style.Position = "absolute";
                         element.Style.Left = property.ValueOnInstance.ToString() + "px";
                         return;
                     }
                 case "Top":
                     {
                         //element.Style.Position = "absolute";
                         element.Style.Top = property.ValueOnInstance.ToString() + "px";
                         return;
                     }
                 case "FontSize":
                     {
                         element.Style.FontSize = property.ValueOnInstance.ToString() + "pt";
                         return;
                     }
                 case "FontWeight":
                     {
                         element.Style.FontWeight = property.ValueOnInstance.ToString();
                         return;
                     }
                 case "RenderTransform":
                     {
                         ParseTransform(element, property.ValueOnInstance as Transform);
                         return;
                     }
                 case "Opacity":
                     {
                         element.Style.Opacity = property.ValueOnInstance.ToString();
                         return;
                     }
                 case "Ignorable":
                     {
                         return;
                     }
                 default:
                     {
                         if (property.ValueOnInstance != null)
                         {
                             var nm = property.PropertyName[0].ToString().ToLower() + property.PropertyName.Substring(1);
                             nm = Regex.Replace(nm, @"(?<!_)([A-Z])", "-$1");
                             element.SetAttribute(nm, property.ValueOnInstance.ToString());
                         }
                         return;
                     }
             }
         }
     }
 }
예제 #19
0
		internal override void AddNodeTo(XamlProperty property)
		{
			if (attribute != null) {
				property.ParentObject.XmlElement.Attributes.Append(attribute);
			} else if (textValue != null) {
				attribute = property.SetAttribute(textValue);
				textValue = null;
			} else if (cDataSection != null) {
				property.AddChildNodeToProperty(cDataSection);
			} else {
				property.AddChildNodeToProperty(textNode);
			}
		}
예제 #20
0
 /// <summary>
 /// Create a XamlPropertyValue for the specified value instance.
 /// </summary>
 public XamlPropertyValue CreatePropertyValue(object instance, XamlProperty forProperty)
 {
     return(CreatePropertyValue(null, instance, forProperty));
 }
예제 #21
0
		internal string GetPrefixForNamespace(string @namespace)
		{
			if (@namespace == XamlConstants.PresentationNamespace)
			{
				return null;
			}

			string prefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(@namespace);

			if (String.IsNullOrEmpty(prefix))
			{
				prefix = _typeFinder.GetPrefixForXmlNamespace(@namespace);

				string existingNamespaceForPrefix = null;
				if (!String.IsNullOrEmpty(prefix))
				{
					existingNamespaceForPrefix = _xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix);
				}

				if (String.IsNullOrEmpty(prefix) ||
				    !String.IsNullOrEmpty(existingNamespaceForPrefix) &&
				    existingNamespaceForPrefix != @namespace)
				{
					do
					{
						prefix = "Controls" + namespacePrefixCounter++;
					} while (!String.IsNullOrEmpty(_xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix)));
				}

				string xmlnsPrefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(XamlConstants.XmlnsNamespace);
				System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(xmlnsPrefix));

				_xmlDoc.DocumentElement.SetAttribute(xmlnsPrefix + ":" + prefix, @namespace);
				
				if (@namespace == XamlConstants.DesignTimeNamespace)
				{
					var ignorableProp = new XamlProperty(this._rootElement,new XamlDependencyPropertyInfo(MarkupCompatibilityProperties.IgnorableProperty,true));
					ignorableProp.SetAttribute(prefix);
				}
			}

			return prefix;
		}
예제 #22
0
		internal abstract void AddNodeTo(XamlProperty property);
예제 #23
0
		/// <summary>
		/// Create a XamlPropertyValue for the specified value instance.
		/// </summary>
		public XamlPropertyValue CreatePropertyValue(object instance, XamlProperty forProperty)
		{
			if (instance == null)
				throw new ArgumentNullException("instance");
			
			Type elementType = instance.GetType();
			TypeConverter c = TypeDescriptor.GetConverter(instance);
			bool hasStringConverter = c.CanConvertTo(typeof(string)) && c.CanConvertFrom(typeof(string));
			
			if (forProperty != null && hasStringConverter) {
				return new XamlTextValue(this, c.ConvertToInvariantString(instance));
			}
			
			
			XmlElement xml = _xmlDoc.CreateElement(elementType.Name, GetNamespaceFor(elementType));
			
			if (hasStringConverter) {
				xml.InnerText = c.ConvertToInvariantString(instance);
			}
			return new XamlObject(this, xml, elementType, instance);
		}
예제 #24
0
		//TODO: reseting path property for binding doesn't work in XamlProperty
		//use CanResetValue()
		internal void OnPropertyChanged(XamlProperty property)
		{			
			UpdateXmlAttribute(false);
			UpdateMarkupExtensionChain();
		}
예제 #25
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			XamlPropertyValue setDefaultValueTo = null;
			object defaultPropertyValue = null;
			XamlProperty defaultCollectionProperty = null;
			
			if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
				obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
			}
			
			foreach (XmlNode childNode in GetNormalizedChildNodes(element)) {
				
				// I don't know why the official XamlReader runs the property getter
				// here, but let's try to imitate it as good as possible
				if (defaultProperty != null && !defaultProperty.IsCollection) {
					for (; combinedNormalizedChildNodes > 0; combinedNormalizedChildNodes--) {
						defaultProperty.GetValue(obj.Instance);
					}
				}
				
				XmlElement childElement = childNode as XmlElement;
				if (childElement != null) {
					if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
						continue;
					
					if (ObjectChildElementIsPropertyElement(childElement)) {
						// I don't know why the official XamlReader runs the property getter
						// here, but let's try to imitate it as good as possible
						if (defaultProperty != null && !defaultProperty.IsCollection) {
							defaultProperty.GetValue(obj.Instance);
						}
						ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
						continue;
					}
				}
				if (initializeFromTextValueInsteadOfConstructor != null)
					continue;
				XamlPropertyValue childValue = ParseValue(childNode);
				if (childValue != null) {
					if (defaultProperty != null && defaultProperty.IsCollection) {
						defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
						CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
					} else {
						if (setDefaultValueTo != null)
							throw new XamlLoadException("default property may have only one value assigned");
						setDefaultValueTo = childValue;
					}
				}
			}
			
			if (defaultProperty != null && !defaultProperty.IsCollection && !element.IsEmpty) {
				// Runs even when defaultValueSet==false!
				// Again, no idea why the official XamlReader does this.
				defaultProperty.GetValue(obj.Instance);
			}
			if (setDefaultValueTo != null) {
				if (defaultProperty == null) {
					throw new XamlLoadException("This element does not have a default value, cannot assign to it");
				}
				obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo));
			}
		}
예제 #26
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			bool isDefaultValueSet = false;
			
			XamlProperty collectionProperty = null;
			object collectionInstance = null;
			Type collectionType = null;
			XmlElement collectionPropertyElement = null;
			var elementChildNodes = GetNormalizedChildNodes(element);
			
			if (defaultProperty == null && obj.Instance != null && CollectionSupport.IsCollectionType(obj.Instance.GetType())) {
				XamlObject parentObj = obj.ParentObject;
				var parentElement = element.ParentNode;
				XamlPropertyInfo propertyInfo;
				if (parentObj != null) {
					propertyInfo = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
					collectionProperty = FindExistingXamlProperty(parentObj, propertyInfo);
				}
				collectionInstance = obj.Instance;
				collectionType = obj.ElementType;
				collectionPropertyElement = element;
			} else if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				foreach (XmlNode childNode in elementChildNodes) {
					currentParsedNode = childNode;
					XmlElement childElement = childNode as XmlElement;
					if (childElement == null || !ObjectChildElementIsPropertyElement(childElement)) {
						obj.AddProperty(collectionProperty = new XamlProperty(obj, defaultProperty));
						collectionType = defaultProperty.ReturnType;
						collectionInstance = defaultProperty.GetValue(obj.Instance);
						break;
					}
				}
			}

			currentParsedNode = element;

			if (collectionType != null && collectionInstance == null && elementChildNodes.Count() == 1)
			{
				var firstChild = elementChildNodes.First() as XmlElement;
				if (ObjectChildElementIsCollectionInstance(firstChild, collectionType))
				{
					collectionInstance = ParseObject(firstChild);
					collectionProperty.PropertyValue = (XamlPropertyValue) collectionInstance;
				}
				else
				{
					throw new XamlLoadException("Collection Instance is null");
				}
			}
			else
			{
				foreach (XmlNode childNode in elementChildNodes) {
					currentParsedNode = childNode;
					XmlElement childElement = childNode as XmlElement;
					if (childElement != null) {
						if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
							continue;
						
						if (ObjectChildElementIsPropertyElement(childElement)) {
							ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty);
							continue;
						}
					}
					if (initializeFromTextValueInsteadOfConstructor != null)
						continue;
					XamlPropertyValue childValue = ParseValue(childNode);
					if (childValue != null) {
						if (collectionProperty != null) {
							collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue);
							CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue);
						} else {
							if (defaultProperty == null)
								throw new XamlLoadException("This element does not have a default value, cannot assign to it");
							
							if (isDefaultValueSet)
								throw new XamlLoadException("default property may have only one value assigned");
							
							obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
							isDefaultValueSet = true;
						}
					}
				}
			}

			currentParsedNode = element;
		}
예제 #27
0
        /// <summary>
        /// Sets an attribute in the x:-namespace.
        /// </summary>
        public void SetXamlAttribute(string name, string value)
        {
            XamlProperty runtimeNameProperty = null;
            bool         isNameChange        = false;

            if (name == "Name")
            {
                isNameChange = true;
                string oldName = GetXamlAttribute("Name");

                if (String.IsNullOrEmpty(oldName))
                {
                    runtimeNameProperty = this.NameProperty;
                    if (runtimeNameProperty != null)
                    {
                        if (runtimeNameProperty.IsSet)
                        {
                            oldName = (string)runtimeNameProperty.ValueOnInstance;
                        }
                        else
                        {
                            runtimeNameProperty = null;
                        }
                    }
                }

                if (String.IsNullOrEmpty(oldName))
                {
                    oldName = null;
                }

                NameScopeHelper.NameChanged(this, oldName, value);
            }

            if (value == null)
            {
                element.RemoveAttribute(name, XamlConstants.XamlNamespace);
            }
            else
            {
                var prefix     = element.GetPrefixOfNamespace(XamlConstants.XamlNamespace);
                var prefix2009 = element.GetPrefixOfNamespace(XamlConstants.Xaml2009Namespace);

                if (!string.IsNullOrEmpty(prefix))
                {
                    var attribute = element.OwnerDocument.CreateAttribute(prefix, name, XamlConstants.XamlNamespace);
                    attribute.InnerText = value;
                    element.SetAttributeNode(attribute);
                }
                else if (!string.IsNullOrEmpty(prefix2009))
                {
                    var attribute = element.OwnerDocument.CreateAttribute(prefix, name, XamlConstants.Xaml2009Namespace);
                    attribute.InnerText = value;
                    element.SetAttributeNode(attribute);
                }
                else
                {
                    element.SetAttribute(name, XamlConstants.XamlNamespace, value);
                }
            }

            if (isNameChange)
            {
                bool nameChangedAlreadyRaised = false;
                if (runtimeNameProperty != null)
                {
                    var handler = new EventHandler((sender, e) => nameChangedAlreadyRaised = true);
                    this.NameChanged += handler;

                    try {
                        runtimeNameProperty.Reset();
                    }
                    finally {
                        this.NameChanged -= handler;
                    }
                }

                if (NameChanged != null && !nameChangedAlreadyRaised)
                {
                    NameChanged(this, EventArgs.Empty);
                }
            }
        }
예제 #28
0
		internal static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute, bool real)
		{
			XamlPropertyInfo propertyInfo = GetPropertyInfo(obj.Instance, obj.ElementType, attribute, obj.OwnerDocument.TypeFinder);
			XamlPropertyValue value = null;

			var valueText = attribute.Value;
			if (valueText.StartsWith("{", StringComparison.Ordinal) && !valueText.StartsWith("{}", StringComparison.Ordinal)) {
				var xamlObject = MarkupExtensionParser.Parse(valueText, obj, real ? attribute : null);
				value = xamlObject;
			} else {
				if (real)
					value = new XamlTextValue(obj.OwnerDocument, attribute);
				else
					value = new XamlTextValue(obj.OwnerDocument, valueText);
			}

			var property = new XamlProperty(obj, propertyInfo, value);
			obj.AddProperty(property);
		}
예제 #29
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            XamlPropertyValue setDefaultValueTo         = null;
            object            defaultPropertyValue      = null;
            XamlProperty      defaultCollectionProperty = null;

            if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
                obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
            }

            foreach (XmlNode childNode in GetNormalizedChildNodes(element))
            {
                // I don't know why the official XamlReader runs the property getter
                // here, but let's try to imitate it as good as possible
                if (defaultProperty != null && !defaultProperty.IsCollection)
                {
                    for (; combinedNormalizedChildNodes > 0; combinedNormalizedChildNodes--)
                    {
                        defaultProperty.GetValue(obj.Instance);
                    }
                }

                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        // I don't know why the official XamlReader runs the property getter
                        // here, but let's try to imitate it as good as possible
                        if (defaultProperty != null && !defaultProperty.IsCollection)
                        {
                            defaultProperty.GetValue(obj.Instance);
                        }
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (defaultProperty != null && defaultProperty.IsCollection)
                    {
                        defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
                        CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
                    }
                    else
                    {
                        if (setDefaultValueTo != null)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }
                        setDefaultValueTo = childValue;
                    }
                }
            }

            if (defaultProperty != null && !defaultProperty.IsCollection && !element.IsEmpty)
            {
                // Runs even when defaultValueSet==false!
                // Again, no idea why the official XamlReader does this.
                defaultProperty.GetValue(obj.Instance);
            }
            if (setDefaultValueTo != null)
            {
                if (defaultProperty == null)
                {
                    throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                }
                obj.AddProperty(new XamlProperty(obj, defaultProperty, setDefaultValueTo));
            }
        }
예제 #30
0
		void ParseObjectChildElementAsPropertyElement(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty)
		{
			Debug.Assert(element.LocalName.Contains("."));
			// this is a element property syntax
			
			XamlPropertyInfo propertyInfo = GetPropertyInfo(settings.TypeFinder, obj.Instance, obj.ElementType, element.NamespaceURI, element.LocalName);
			bool valueWasSet = false;
			
			object collectionInstance = null;
			bool isElementChildACollectionForProperty = false;
			XamlProperty collectionProperty = null;
			if (propertyInfo.IsCollection) {
				if (defaultProperty != null && defaultProperty.FullyQualifiedName == propertyInfo.FullyQualifiedName) {
					foreach (XamlProperty existing in obj.Properties) {
						if (existing.propertyInfo == defaultProperty) {
							collectionProperty = existing;
							break;
						}
					}
				}
				
				if (collectionProperty == null) {
					obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo));
				}
				
				isElementChildACollectionForProperty = IsElementChildACollectionForProperty(settings.TypeFinder, element, propertyInfo);
				if (isElementChildACollectionForProperty)
					collectionProperty.ParserSetPropertyElement((XmlElement)element.ChildNodes.Cast<XmlNode>().Where(x => !(x is XmlWhitespace)).First());
				else {
					collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance);
					collectionProperty.ParserSetPropertyElement(element);
					collectionInstance = collectionInstance ?? Activator.CreateInstance(collectionProperty.propertyInfo.ReturnType);
				}
			}
			
			XmlSpace oldXmlSpace = currentXmlSpace;
			if (element.HasAttribute("xml:space")) {
				currentXmlSpace = (XmlSpace)Enum.Parse(typeof(XmlSpace), element.GetAttribute("xml:space"), true);
			}
			
			foreach (XmlNode childNode in element.ChildNodes) {
				currentParsedNode = childNode;
				XamlPropertyValue childValue = ParseValue(childNode);
				if (childValue != null) {
					if (propertyInfo.IsCollection) {
						if (isElementChildACollectionForProperty) {
							collectionProperty.PropertyValue = childValue;
						}
						else {
							CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
							collectionProperty.ParserAddCollectionElement(element, childValue);
						}
					} else {
						if (valueWasSet)
							throw new XamlLoadException("non-collection property may have only one child element");
						valueWasSet = true;
						XamlProperty xp = new XamlProperty(obj, propertyInfo, childValue);
						xp.ParserSetPropertyElement(element);
						obj.AddProperty(xp);
					}
				}
			}

			currentParsedNode = element;

			currentXmlSpace = oldXmlSpace;
		}
예제 #31
0
		/// <summary>
		/// Create a XamlPropertyValue for the specified value instance.
		/// </summary>
		public XamlPropertyValue CreatePropertyValue(object instance, XamlProperty forProperty)
		{
			if (instance == null)
				throw new ArgumentNullException("instance");
			
			Type elementType = instance.GetType();
			TypeConverter c = TypeDescriptor.GetConverter(instance);
			var ctx = new DummyTypeDescriptorContext(this.ServiceProvider);
			ctx.Instance = instance;
			bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string));
			if (forProperty != null && hasStringConverter) {
				return new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance));
			}

			string ns = GetNamespaceFor(elementType);
			string prefix = GetPrefixForNamespace(ns);
			
			XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);

			if (hasStringConverter && XamlObject.GetContentPropertyName(elementType) != null) {
				xml.InnerText = c.ConvertToInvariantString(instance);
			} else if (instance is Brush && forProperty != null) {  // TODO: this is a hacky fix, because Brush Editor doesn't
										     // edit Design Items and so we have no XML, only the Brush 
										     // object and we need to parse the Brush to XAML!
				var s = new MemoryStream();
				XamlWriter.Save(instance, s);
				s.Seek(0, SeekOrigin.Begin);
				XmlDocument doc = new XmlDocument();
				doc.Load(s);
				xml = (XmlElement)_xmlDoc.ImportNode(doc.DocumentElement, true);

				var attLst = xml.Attributes.Cast<XmlAttribute>().ToList();
				foreach (XmlAttribute att in attLst) {
					if (att.Name.StartsWith(XamlConstants.Xmlns)) {
						var rootAtt = doc.DocumentElement.GetAttributeNode(att.Name);
						if (rootAtt != null && rootAtt.Value == att.Value) {
							xml.Attributes.Remove(att);
						}
					}
				}
			} else if (instance is string) {
				xml.InnerText = (string)instance;
			}

			return new XamlObject(this, xml, elementType, instance);
		}
예제 #32
0
		internal override void AddNodeTo(XamlProperty property)
		{
			XamlObject holder;
			if (!UpdateXmlAttribute(true, out holder)) {
				property.AddChildNodeToProperty(element);
			}
			UpdateMarkupExtensionChain();
		}
예제 #33
0
        void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
        {
            bool isDefaultValueSet = false;

            XamlProperty collectionProperty        = null;
            object       collectionInstance        = null;
            Type         collectionType            = null;
            XmlElement   collectionPropertyElement = null;
            var          elementChildNodes         = GetNormalizedChildNodes(element);

            if (defaultProperty == null && obj.Instance != null && CollectionSupport.IsCollectionType(obj.Instance.GetType()))
            {
                XamlObject       parentObj     = obj.ParentObject;
                var              parentElement = element.ParentNode;
                XamlPropertyInfo propertyInfo  = GetPropertyInfo(settings.TypeFinder, parentObj.Instance, parentObj.ElementType, parentElement.NamespaceURI, parentElement.LocalName);
                collectionProperty        = FindExistingXamlProperty(parentObj, propertyInfo);
                collectionInstance        = obj.Instance;
                collectionType            = obj.ElementType;
                collectionPropertyElement = element;
            }
            else if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty)
            {
                foreach (XmlNode childNode in elementChildNodes)
                {
                    XmlElement childElement = childNode as XmlElement;
                    if (childElement == null || !ObjectChildElementIsPropertyElement(childElement))
                    {
                        obj.AddProperty(collectionProperty = new XamlProperty(obj, defaultProperty));
                        collectionType     = defaultProperty.ReturnType;
                        collectionInstance = defaultProperty.GetValue(obj.Instance);
                        break;
                    }
                }
            }

            foreach (XmlNode childNode in elementChildNodes)
            {
                XmlElement childElement = childNode as XmlElement;
                if (childElement != null)
                {
                    if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
                    {
                        continue;
                    }

                    if (ObjectChildElementIsPropertyElement(childElement))
                    {
                        ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty);
                        continue;
                    }
                }
                if (initializeFromTextValueInsteadOfConstructor != null)
                {
                    continue;
                }
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (collectionProperty != null)
                    {
                        collectionProperty.ParserAddCollectionElement(collectionPropertyElement, childValue);
                        CollectionSupport.AddToCollection(collectionType, collectionInstance, childValue);
                    }
                    else
                    {
                        if (defaultProperty == null)
                        {
                            throw new XamlLoadException("This element does not have a default value, cannot assign to it");
                        }

                        if (isDefaultValueSet)
                        {
                            throw new XamlLoadException("default property may have only one value assigned");
                        }

                        obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
                        isDefaultValueSet = true;
                    }
                }
            }
        }
예제 #34
0
		//TODO: reseting path property for binding doesn't work in XamlProperty
		//use CanResetValue()
		internal void OnPropertyChanged(XamlProperty property)
		{
			XamlObject holder;
			if (!UpdateXmlAttribute(false, out holder)) {
				if (holder != null &&
				    holder.XmlAttribute != null) {
					holder.XmlAttribute.OwnerElement.RemoveAttributeNode(holder.XmlAttribute);
					holder.xmlAttribute = null;
					holder.ParentProperty.AddChildNodeToProperty(holder.element);
					
					bool isThisUpdated = false;
					foreach(XamlObject propXamlObject in holder.Properties.Where((prop) => prop.IsSet).Select((prop) => prop.PropertyValue).OfType<XamlObject>()) {
						XamlObject innerHolder;
						bool updateResult = propXamlObject.UpdateXmlAttribute(true, out innerHolder);
						Debug.Assert(updateResult);
						
						if (propXamlObject == this)
							isThisUpdated = true;
					}
					if (!isThisUpdated)
						this.UpdateXmlAttribute(true, out holder);
				}
			}
			UpdateMarkupExtensionChain();
			
			if (property == NameProperty) {
				if (NameChanged != null)
					NameChanged(this, EventArgs.Empty);
			}
		}
예제 #35
0
        void ParseObjectChildElementAsPropertyElement(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty)
        {
            Debug.Assert(element.LocalName.Contains("."));
            // this is a element property syntax

            XamlPropertyInfo propertyInfo = GetPropertyInfo(settings.TypeFinder, obj.Instance, obj.ElementType, element.NamespaceURI, element.LocalName);
            bool             valueWasSet  = false;

            object       collectionInstance = null;
            bool         isElementChildACollectionForProperty = false;
            XamlProperty collectionProperty = null;

            if (propertyInfo.IsCollection)
            {
                if (defaultProperty != null && defaultProperty.FullyQualifiedName == propertyInfo.FullyQualifiedName)
                {
                    foreach (XamlProperty existing in obj.Properties)
                    {
                        if (existing.propertyInfo == defaultProperty)
                        {
                            collectionProperty = existing;
                            break;
                        }
                    }
                }

                if (collectionProperty == null)
                {
                    obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo));
                }

                isElementChildACollectionForProperty = IsElementChildACollectionForProperty(settings.TypeFinder, element, propertyInfo);
                if (isElementChildACollectionForProperty)
                {
                    collectionProperty.ParserSetPropertyElement((XmlElement)element.FirstChild);
                }
                else
                {
                    collectionInstance = collectionProperty.propertyInfo.GetValue(obj.Instance);
                    collectionProperty.ParserSetPropertyElement(element);
                }
            }

            XmlSpace oldXmlSpace = currentXmlSpace;

            if (element.HasAttribute("xml:space"))
            {
                currentXmlSpace = (XmlSpace)Enum.Parse(typeof(XmlSpace), element.GetAttribute("xml:space"), true);
            }

            foreach (XmlNode childNode in element.ChildNodes)
            {
                XamlPropertyValue childValue = ParseValue(childNode);
                if (childValue != null)
                {
                    if (propertyInfo.IsCollection)
                    {
                        if (isElementChildACollectionForProperty)
                        {
                            collectionProperty.PropertyValue = childValue;
                        }
                        else
                        {
                            CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
                            collectionProperty.ParserAddCollectionElement(element, childValue);
                        }
                    }
                    else
                    {
                        if (valueWasSet)
                        {
                            throw new XamlLoadException("non-collection property may have only one child element");
                        }
                        valueWasSet = true;
                        XamlProperty xp = new XamlProperty(obj, propertyInfo, childValue);
                        xp.ParserSetPropertyElement(element);
                        obj.AddProperty(xp);
                    }
                }
            }

            currentXmlSpace = oldXmlSpace;
        }
예제 #36
0
		/// <summary>
		/// Finds the specified property, or creates it if it doesn't exist.
		/// </summary>
		public XamlProperty FindOrCreateProperty(string propertyName)
		{
			if (propertyName == null)
				throw new ArgumentNullException("propertyName");
			
//			if (propertyName == ContentPropertyName)
//				return
			
			foreach (XamlProperty p in properties) {
				if (!p.IsAttached && p.PropertyName == propertyName)
					return p;
			}
			PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(instance);
			PropertyDescriptor propertyInfo = propertyDescriptors[propertyName];
			XamlProperty newProperty;
			if (propertyInfo != null) {
				newProperty = new XamlProperty(this, new XamlNormalPropertyInfo(propertyInfo));
			} else {
				EventDescriptorCollection events = TypeDescriptor.GetEvents(instance);
				EventDescriptor eventInfo = events[propertyName];
				if (eventInfo != null) {
					newProperty = new XamlProperty(this, new XamlEventPropertyInfo(eventInfo));
				} else {
					throw new ArgumentException("The property '" + propertyName + "' doesn't exist on " + elementType.FullName, "propertyName");
				}
			}
			properties.Add(newProperty);
			return newProperty;
		}
예제 #37
0
 internal CollectionElementsCollection(XamlProperty property)
 {
     this.property = property;
 }
예제 #38
0
		void ParseObjectContent(XamlObject obj, XmlElement element, XamlPropertyInfo defaultProperty, XamlTextValue initializeFromTextValueInsteadOfConstructor)
		{
			bool isDefaultValueSet = false;
			object defaultPropertyValue = null;
			XamlProperty defaultCollectionProperty = null;
			
			if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
				defaultPropertyValue = defaultProperty.GetValue(obj.Instance);
				obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
			}
			
			foreach (XmlNode childNode in GetNormalizedChildNodes(element)) {
				XmlElement childElement = childNode as XmlElement;
				if (childElement != null) {
					if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
						continue;
					
					if (ObjectChildElementIsPropertyElement(childElement)) {
						ParseObjectChildElementAsPropertyElement(obj, childElement, defaultProperty, defaultPropertyValue);
						continue;
					}
				}
				if (initializeFromTextValueInsteadOfConstructor != null)
					continue;
				XamlPropertyValue childValue = ParseValue(childNode);
				if (childValue != null) {
					if (defaultProperty != null && defaultProperty.IsCollection) {
						defaultCollectionProperty.ParserAddCollectionElement(null, childValue);
						CollectionSupport.AddToCollection(defaultProperty.ReturnType, defaultPropertyValue, childValue);
					} else {
						if (defaultProperty == null)
							throw new XamlLoadException("This element does not have a default value, cannot assign to it");
						
						if (isDefaultValueSet)
							throw new XamlLoadException("default property may have only one value assigned");
						
						obj.AddProperty(new XamlProperty(obj, defaultProperty, childValue));
						isDefaultValueSet = true;
					}
				}
			}
		}