Ejemplo n.º 1
0
        public static object ConvertObject(XamlParser parser, XamlObjectElement element, Type dest_type, TypeConverter converter, string prop_name, object val)
        {
            // Should i return default(T) if property.PropertyType is a valuetype?
            if (val == null)
            {
                return(val);
            }

            if (dest_type.IsAssignableFrom(val.GetType()))
            {
                return(val);
            }

            if (dest_type == typeof(string))
            {
                return(val.ToString());
            }

            if (converter == null || ConverterIsBlackListed(converter))
            {
                converter = new XamlTypeConverter(parser, element, prop_name, dest_type);
            }

            return(converter.ConvertFrom(null, Helper.DefaultCulture, val));
        }
Ejemplo n.º 2
0
        private void AddChildObject(XamlObjectElement obj)
        {
            object        value   = obj.Object;
            MutableObject mutable = value as MutableObject;

            if (mutable != null)
            {
                value = mutable.Object;
            }

            IList list = Object as IList;

            if (list != null)
            {
                list.Add(value);
                return;
            }

            IDictionary dict = Object as IDictionary;

            if (dict != null)
            {
                dict.Add(obj.GetDictionaryKey(), value);
                return;
            }

            XamlReflectionPropertySetter content_property = FindContentProperty();

            if (content_property == null)
            {
                throw Parser.ParseException("Unable to add element {0} to element {1}.", obj.Name, Name);
            }

            content_property.SetValue(value);
        }
Ejemplo n.º 3
0
        private static Type GetTargetType(XamlTypeConverter converter)
        {
            XamlElement       p      = converter.parser.CurrentElement.Parent;
            XamlObjectElement parent = p as XamlObjectElement;

            if (p == null)
            {
                throw new XamlParseException("Attempting to create a DP from an item without a target property.");
            }

            if (parent == null)
            {
                parent = p.Parent as XamlObjectElement;
            }
            if (parent == null)
            {
                throw new XamlParseException("Attempting to create a DP from an item without a target property.");
            }

            Style s = parent.Object as Style;

            if (s == null)
            {
                throw new XamlParseException("Attempting to create a DP from a non style object.");
            }

            return(s.TargetType);
        }
Ejemplo n.º 4
0
 public static XamlReflectionPropertySetter Create(XamlObjectElement element, object target, Accessors accessors)
 {
     if (accessors == null)
     {
         return(null);
     }
     return(new XamlReflectionPropertySetter(element, target, accessors));
 }
Ejemplo n.º 5
0
 public static XamlAttachedPropertySetter Create(XamlObjectElement element, Accessors accessors)
 {
     if (accessors == null)
     {
         return(null);
     }
     return(new XamlAttachedPropertySetter(element, accessors));
 }
Ejemplo n.º 6
0
        static Accessors CreateAttachedAccessors(XamlObjectElement parent, Type t, string name)
        {
            // See comment in XamlReflectionPropertyForName to see why we special case the case
            // where there's a DP but no static getter/setter methods.

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            Func <TypeConverter> converter = null;
            MethodInfo           getter    = ResolveAttachedPropertyGetter(name, t);
            MethodInfo           setter    = ResolveAttachedPropertySetter(name, t, getter == null ? null : getter.ReturnType);

            if (getter != null)
            {
                converter = Helper.GetConverterCreatorFor(getter, getter.ReturnType);
            }

            if ((getter == null && setter == null) || (setter == null && !IsCollectionType(getter.ReturnType)))
            {
                if (Deployment.Current.MajorVersion >= 4)
                {
                    // The SL4+ parser will not allow you to set a Binding on DP with no CLR wrapper
                    return(null);
                }

                // The old parser will allow you to set a Binding on DP with no CLR wrapper
                DependencyProperty dp;
                Types.Ensure(t);
                if (DependencyProperty.TryLookup(Deployment.Current.Types.TypeToKind(t), name, out dp) && dp.IsAttached)
                {
                    return(new Accessors(
                               (o) => { throw new XamlParseException(string.Format("The property {0} was not found on element {1}.", name, t.Name)); },
                               (o, a) => { throw new XamlParseException(string.Format("The property {0} was not found on element {1}.", name, t.Name)); },
                               dp.PropertyType,
                               dp.Name,
                               converter,
                               dp.DeclaringType
                               ));
                }
                else
                {
                    return(null);
                }
            }

            return(new Accessors(
                       CreateAttachedGetter(getter),
                       CreateAttachedSetter(setter),
                       getter != null ? getter.ReturnType : setter.GetParameters() [1].ParameterType,
                       name,
                       converter,
                       getter != null ? getter.DeclaringType : setter.DeclaringType
                       ));
        }
Ejemplo n.º 7
0
        XamlReflectionPropertySetter(XamlObjectElement element, object target, Accessors accessors) : base(element, accessors.Name, accessors.ConverterCreator == null ? null : accessors.ConverterCreator())
        {
            this.target    = target;
            this.accessors = accessors;

            if (target is MutableObject)
            {
                is_mutable = true;
            }
        }
Ejemplo n.º 8
0
        private void AddToCollection(XamlObjectElement obj, object value)
        {
            IList list = accessors.Getter(target) as IList;

            if (list == null)
            {
                throw Parser.ParseException("Collection property in non collection type.");
            }

            list.Add(value);
        }
Ejemplo n.º 9
0
        public override void SetValue(XamlObjectElement obj, object value)
        {
            MutableObject mutable = value as MutableObject;

            if (mutable != null)
            {
                value = mutable.Object;
            }

            Binding binding = value as Binding;

            if (binding != null && SetBinding(binding, Target))
            {
                return;
            }

            if (!typeof(TemplateBindingExpression).IsAssignableFrom(Type))
            {
                TemplateBindingExpression tb = value as TemplateBindingExpression;
                if (tb != null)
                {
                    SetTemplateBinding(tb, Target);
                    return;
                }
            }

            // We do this before lists to cover the case where you are setting a list to a list or
            // a resource dictionary to a resource dictionary, ect
            // as opposed to adding items to the list or dictionary.
            //
            // null is a legal value here because they may have done something like foo="{x:Null}"
            //
            if (value == null || Type.IsAssignableFrom(value.GetType()))
            {
                accessors.Setter(Target, ConvertValue(Type, value));
                return;
            }

            if (typeof(IList).IsAssignableFrom(Type))
            {
                AddToCollection(obj, value);
                return;
            }

            if (typeof(IDictionary).IsAssignableFrom(Type))
            {
                AddToDictionary(obj, value);
                return;
            }

            throw Parser.ParseException("Unable to set property {0} to value {1}.", Name, value);
        }
Ejemplo n.º 10
0
        public override void SetValue(XamlObjectElement obj, object value)
        {
            var mutable = value as MutableObject;

            if (mutable != null)
            {
                value = mutable.Object;
            }

            if (!typeof(Binding).IsAssignableFrom(Type))
            {
                Binding binding = value as Binding;
                if (binding != null)
                {
                    SetBinding(binding, Element.Object);
                    return;
                }
            }

            if (!typeof(TemplateBindingExpression).IsAssignableFrom(Type))
            {
                TemplateBindingExpression tb = value as TemplateBindingExpression;
                if (tb != null)
                {
                    SetTemplateBinding(tb, obj.Object);
                    return;
                }
            }

            if (value == null || Type.IsAssignableFrom(value.GetType()))
            {
                Accessors.Setter(Element.Object, ConvertValue(Type, value));
                return;
            }

            if (typeof(IList).IsAssignableFrom(Type))
            {
                AddToCollection(value);
                return;
            }

            throw new XamlParseException(
                      string.Format("XamlAttachedPropertySetter.SetValue: Could not set value '{0}' to the attached property '{1}.{2}'",
                                    value,
                                    Accessors.DeclaringType,
                                    Accessors.Name)
                      );
        }
Ejemplo n.º 11
0
        public override void AddChild(XamlElement child)
        {
            if (!set_on_add)
            {
                return;
            }

            XamlObjectElement element = child as XamlObjectElement;

            if (element == null)
            {
                return;
            }

            Setter.SetValue(element, element.Object);
        }
Ejemplo n.º 12
0
        private void AddToDictionary(XamlObjectElement obj, object value)
        {
            IDictionary rd = accessors.Getter(target) as IDictionary;

            if (rd == null)
            {
                throw Parser.ParseException("Collection property in non collection type.");
            }

            string key = obj.GetDictionaryKey();

            if (key == null)
            {
                throw Parser.ParseException("You must specify an x:Key or x:Name for elements in a ResourceDictionary");
            }

            rd.Add(key, value);
        }
Ejemplo n.º 13
0
        public override void SetValue(XamlObjectElement obj, object value)
        {
            if (value == null)
            {
                throw Parser.ParseException("Setting Name value to null.");
            }

            string name = value as string;

            if (name == null)
            {
                throw Parser.ParseException("Unable to set Name property to type {1}.", value.GetType());
            }

            obj.X_Name = name;

            if (!target.SetNameOnScope(name, Parser.NameScope))
            {
                throw Parser.ParseException("Unable to set Name '{0}' on element '{1}'.", name, Element.Name);
            }
        }
Ejemplo n.º 14
0
		public XamlNamePropertySetter (XamlObjectElement element, DependencyObject target) : base (element, "Name", null)
		{
			this.target = target;
		}
Ejemplo n.º 15
0
		public XamlReflectionEventSetter (XamlObjectElement element, object target, EventInfo evnt) : base (element, evnt.Name,
				Helper.GetConverterFor (evnt, evnt.EventHandlerType))
		{
			this.target = target;
			this.evnt = evnt;
		}
Ejemplo n.º 16
0
		private void AddToCollection (XamlObjectElement obj, object value)
		{
			IList list = accessors.Getter (target) as IList;
			if (list == null) {
				throw Parser.ParseException ("Collection property in non collection type.");
			}

			list.Add (value);
		}
Ejemplo n.º 17
0
		XamlReflectionPropertySetter (XamlObjectElement element, object target, Accessors accessors) : base (element, accessors.Name, accessors.ConverterCreator == null ? null : accessors.ConverterCreator ())
		{
			this.target = target;
			this.accessors = accessors;

			if (target is MutableObject)
				is_mutable = true;
		}
Ejemplo n.º 18
0
		public abstract void SetValue (XamlObjectElement obj, object value);
Ejemplo n.º 19
0
        public override void SetValue(XamlObjectElement obj, object value)
        {
            MethodInfo invoker_info = evnt.EventHandlerType.GetMethod("Invoke");

            ParameterInfo [] event_params = invoker_info.GetParameters();
            string           handler_name = value as string;
            var subscriber = Parser.TopElement;

            if (subscriber == null)
            {
                throw Parser.ParseException("Attempt to set an event handler on an invalid object.");
            }

            if (String.IsNullOrEmpty(handler_name))
            {
                throw Parser.ParseException("Attmept to set an event handler to null.");
            }


            Delegate d = null;

            MethodInfo [] methods    = subscriber.GetType().GetMethods(XamlParser.EVENT_BINDING_FLAGS);
            MethodInfo    candidate  = null;
            bool          name_match = false;

            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo       m = methods [i];
                ParameterInfo [] parameters;

                if (m.Name != handler_name)
                {
                    continue;
                }

                if (name_match)
                {
                    throw Parser.ParseException("Multiple event handlers found with same name.");
                }

                name_match = true;

                parameters = m.GetParameters();
                if (parameters.Length != event_params.Length)
                {
                    continue;
                }

                bool match = true;
                for (int p = 0; p < parameters.Length; p++)
                {
                    if (!event_params [p].ParameterType.IsSubclassOf(parameters [p].ParameterType) && parameters [p].ParameterType != event_params [p].ParameterType)
                    {
                        Console.Error.WriteLine("mismatch:  {0}  and {1}", parameters [p].ParameterType, event_params [p].ParameterType);
                        match = false;
                        break;
                    }
                }

                if (!match)
                {
                    continue;
                }

                if (candidate != null)
                {
                    throw Parser.ParseException("Multiple event handler candidates found for event {0}", Name);
                }

                candidate = m;
            }

            if (candidate == null)
            {
                throw Parser.ParseException("Event handler not found for event {0}.", Name);
            }

            d = Delegate.CreateDelegate(evnt.EventHandlerType, subscriber, candidate, false);
            if (d == null)
            {
                throw Parser.ParseException("Unable to create event delegate for event {0}.", Name);
            }

            evnt.AddEventHandler(target, d);
        }
Ejemplo n.º 20
0
 public XamlNamePropertySetter(XamlObjectElement element, DependencyObject target) : base(element, "Name", null)
 {
     this.target = target;
 }
Ejemplo n.º 21
0
		public static XamlAttachedPropertySetter Create (XamlObjectElement element, Accessors accessors)
		{
			if (accessors == null)
				return null;
			return new XamlAttachedPropertySetter (element, accessors);
		}
Ejemplo n.º 22
0
 protected XamlPropertySetter(XamlObjectElement element, string name, TypeConverter converter)
 {
     Element   = element;
     Name      = name;
     Converter = converter;
 }
Ejemplo n.º 23
0
 XamlAttachedPropertySetter(XamlObjectElement element, Accessors accessors)
     : base(element, accessors.Name, accessors.ConverterCreator == null ? null : accessors.ConverterCreator())
 {
     Accessors = accessors;
 }
Ejemplo n.º 24
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			var mutable = value as MutableObject;
			if (mutable != null)
				value = mutable.Object;

			if (!typeof (Binding).IsAssignableFrom (Type)) {
				Binding binding = value as Binding;
				if (binding != null) {
					SetBinding (binding, Element.Object);
					return;
				}
			}

			if (!typeof (TemplateBindingExpression).IsAssignableFrom (Type)) {
				TemplateBindingExpression tb = value as TemplateBindingExpression;
				if (tb != null) {
					SetTemplateBinding (tb, obj.Object);
					return;
				}
			}

			if (value == null || Type.IsAssignableFrom (value.GetType ())) {
				Accessors.Setter (Element.Object, ConvertValue (Type, value));
				return;
			}
				
			if (typeof (IList).IsAssignableFrom (Type)) {
				AddToCollection (value);
				return;
			}

			throw new XamlParseException (
				string.Format ("XamlAttachedPropertySetter.SetValue: Could not set value '{0}' to the attached property '{1}.{2}'",
					value,
					Accessors.DeclaringType,
					Accessors.Name)
			);
		}
Ejemplo n.º 25
0
 public XamlTypeConverter(XamlParser parser, XamlObjectElement element, string propertyName, Type destinationType) : base(propertyName, destinationType)
 {
     this.parser  = parser;
     this.element = element;
 }
Ejemplo n.º 26
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			// We do this first to cover the case where you are setting a list to a list or
			// a resource dictionary to a resource dictionary, binding to a binding, ect
			// as opposed to adding items to the list or dictionary.
			if (Type.IsAssignableFrom (value.GetType ())) {
				prop.SetValue (target, ConvertValue (Type, value), null);
				return;
			}

			{
				Binding binding = value as Binding;
				if (binding != null) {
					SetBinding (binding);
					return;
				}
			}

			{
				TemplateBindingExpression tb = value as TemplateBindingExpression;
				if (tb != null) {
					SetTemplateBinding (tb);
					return;
				}
			}

			if (typeof (IList).IsAssignableFrom (Type)) {
				AddToCollection (obj, value);
				return;
			}

			if (typeof (IDictionary).IsAssignableFrom (Type)) {
				AddToDictionary (obj, value);
				return;
			}

			throw Parser.ParseException ("Unable to set property {0} to value {1}.", Name, value);
		}
Ejemplo n.º 27
0
		public XamlAttachedPropertySetter (XamlObjectElement element, string name, MethodInfo getter, MethodInfo setter) : base (element, name, Helper.GetConverterFor (setter, getter.ReturnType))
		{
			this.getter = getter;
			this.setter = setter;
		}
Ejemplo n.º 28
0
 public SL4MarkupExpressionParser(object target, string attribute_name, XamlParser parser, XamlObjectElement target_element) : base(target, attribute_name)
 {
     this.parser         = parser;
     this.target_element = target_element;
 }
Ejemplo n.º 29
0
 public XamlReflectionEventSetter(XamlObjectElement element, object target, EventInfo evnt) : base(element, evnt.Name,
                                                                                                   Helper.GetConverterFor(evnt, evnt.EventHandlerType))
 {
     this.target = target;
     this.evnt   = evnt;
 }
Ejemplo n.º 30
0
		internal void RegisterKeyItem (XamlObjectElement element, XamlElement target, string key)
		{
			IDictionary rd = CurrentDictionary (element);
			if (rd == null)
				throw ParseException ("Attempt to use x:Key outside of an IDictionary.");

			element.X_Key = key;
		}
Ejemplo n.º 31
0
		internal void RegisterNamedItem (XamlObjectElement element, string name)
		{
			IDictionary rd = CurrentDictionary (element);
			if (rd != null && element.X_Key != null) {
				throw ParseException ("The name already exists in the tree.");
			}

			if (element.X_Name != null) {
				throw ParseException ("Cannot specify both Name and x:Name attributes.");
			}

			element.X_Name = name;

			FrameworkElement fe = element.FrameworkElement;
			if (fe != null)
				fe.SetNameOnScope (name, NameScope);
		}
Ejemplo n.º 32
0
		public XamlReflectionPropertySetter (XamlObjectElement element, object target, PropertyInfo prop) : base (element, prop.Name, Helper.GetConverterFor (prop, prop.PropertyType))
		{
			this.target = target;
			this.prop = prop;
		}
Ejemplo n.º 33
0
		private void ParseObjectElement ()
		{
			Type t = ResolveType ();
			if (t == null)
				throw ParseException ("Unable to find the type {0}.", reader.LocalName);

			object o = InstantiateType (t);

			XamlObjectElement element = new XamlObjectElement (this, reader.LocalName, o);

			SetElementTemplateScopes (element);
			OnElementBegin (element);
			
			ParseElementAttributes (element);

			// This is a self closing element ie <Rectangle />
			if (reader.IsEmptyElement)
				OnElementEnd ();
		}
Ejemplo n.º 34
0
		private void AddToDictionary (XamlObjectElement obj, object value)
		{
			IDictionary rd = prop.GetValue (target, null) as IDictionary;
			if (rd == null)
				throw Parser.ParseException ("Collection property in non collection type.");

			rd.Add (obj.X_Key, value);
		}
Ejemplo n.º 35
0
		private void ParseTemplateElement ()
		{
			Type t = ResolveType ();
			if (t == null)
				throw ParseException ("Unable to find the type {0}", t);
			object o = InstantiateType (t);

			XamlObjectElement element = new XamlObjectElement (this, reader.LocalName, o);
			OnElementBegin (element);
			
			ParseElementAttributes (element);

			string template_xml = reader.ReadInnerXml ();
			
			FrameworkTemplate template = o as FrameworkTemplate;

			unsafe {
				template.SetXamlBuffer (ParseTemplate, CreateXamlContext (template), template_xml);
			}

			//
			// ReadInnerXml will read our closing </ControlTemplate> tag also, so we manually close things
			//
			OnElementEnd ();
		}
Ejemplo n.º 36
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			setter.Invoke (null, new object [] { Element.Object, value });
		}
Ejemplo n.º 37
0
		private void ParseTextBlockText (XamlObjectElement block)
		{
		}
Ejemplo n.º 38
0
		public static XamlReflectionPropertySetter Create (XamlObjectElement element, object target, Accessors accessors)
		{
			if (accessors == null)
				return null;
			return new XamlReflectionPropertySetter (element, target, accessors);
		}
Ejemplo n.º 39
0
		private void ParseElementAttributes (XamlObjectElement element)
		{
			if (!reader.HasAttributes)
				return;

			try {
				int ac = reader.AttributeCount;
				for (int i = 0; i < reader.AttributeCount; i++) {
					reader.MoveToAttribute (i);
					ParseAttribute (element);
				}
			} finally {
				// We do this in a finally so error reporting doesn't get all jacked up
				reader.MoveToElement();
			}
		}
Ejemplo n.º 40
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			MutableObject mutable = value as MutableObject;
			if (mutable != null)
				value = mutable.Object;

			Binding binding = value as Binding;
			if (binding != null && SetBinding (binding, Target))
				return;

			if (!typeof (TemplateBindingExpression).IsAssignableFrom (Type)) {
				TemplateBindingExpression tb = value as TemplateBindingExpression;
				if (tb != null) {
					SetTemplateBinding (tb, Target);
					return;
				}
			}

			// We do this before lists to cover the case where you are setting a list to a list or
			// a resource dictionary to a resource dictionary, ect
			// as opposed to adding items to the list or dictionary.
			//
			// null is a legal value here because they may have done something like foo="{x:Null}"
			//
			if (value == null || Type.IsAssignableFrom (value.GetType ())) {
				accessors.Setter (Target, ConvertValue (Type, value));
				return;
			}

			if (typeof (IList).IsAssignableFrom (Type)) {
				AddToCollection (obj, value);
				return;
			}

			if (typeof (IDictionary).IsAssignableFrom (Type)) {
				AddToDictionary (obj, value);
				return;
			}

			throw Parser.ParseException ("Unable to set property {0} to value {1}.", Name, value);
		}
Ejemplo n.º 41
0
		private void ParseAttribute (XamlObjectElement element)
		{
			if (IsMcAttribute ()) {
				ParseMcAttribute (element);
				return;
			}
			if (IsXmlnsMapping ()) {
				ParseXmlnsMapping (element);
				return;
			}

			if (IsXAttribute ()) {
				ParseXAttribute (element);
				return;
			}

			if (IsXmlDirective ()) {
				ParseXmlDirective (element);
				return;
			}

			if (IsIgnorable ()) {
				return;
			}

			XamlPropertySetter prop = element.LookupProperty (reader);
			if (prop == null)
				throw ParseException ("The property {0} was not found.", reader.LocalName);
			object value = ParseAttributeValue (element, prop);
			prop.SetValue (value);
		}
Ejemplo n.º 42
0
		private void AddToDictionary (XamlObjectElement obj, object value)
		{
			IDictionary rd = accessors.Getter (target) as IDictionary;
			if (rd == null)
				throw Parser.ParseException ("Collection property in non collection type.");

			string key = obj.GetDictionaryKey ();
			if (key == null)
				throw Parser.ParseException ("You must specify an x:Key or x:Name for elements in a ResourceDictionary");

			rd.Add (key, value);
		}
Ejemplo n.º 43
0
		private void ParseXAttribute (XamlObjectElement element)
		{
			switch (reader.LocalName) {
			case "Key":
				RegisterKeyItem (element, element.Parent, reader.Value);
				return;
			case "Name":
				RegisterNamedItem (element, reader.Value);
				return;
			case "Class":
				// The class attribute is handled when we initialize the element
				return;
			default:
				throw ParseException ("Unknown x: attribute ({0}).", reader.LocalName);
			}
		}
Ejemplo n.º 44
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			MethodInfo invoker_info = evnt.EventHandlerType.GetMethod ("Invoke");
			ParameterInfo [] event_params = invoker_info.GetParameters ();
			string handler_name = value as string;
			var subscriber = Parser.TopElement;

			if (subscriber == null)
				throw Parser.ParseException ("Attempt to set an event handler on an invalid object.");

			if (String.IsNullOrEmpty (handler_name))
				throw Parser.ParseException ("Attmept to set an event handler to null.");


			Delegate d = null;
			MethodInfo [] methods = subscriber.GetType ().GetMethods (XamlParser.EVENT_BINDING_FLAGS);
			MethodInfo candidate = null;
			bool name_match = false;

			for (int i = 0; i < methods.Length; i++) {
				MethodInfo m = methods [i];
				ParameterInfo [] parameters;
				
				if (m.Name != handler_name)
					continue;

				if (name_match)
					throw Parser.ParseException ("Multiple event handlers found with same name.");

				name_match = true;

				parameters = m.GetParameters ();
				if (parameters.Length != event_params.Length)
					continue;

				bool match = true;
				for (int p = 0; p < parameters.Length; p++) {
					if (!event_params [p].ParameterType.IsSubclassOf (parameters [p].ParameterType) && parameters [p].ParameterType != event_params [p].ParameterType) {
						Console.Error.WriteLine ("mismatch:  {0}  and {1}", parameters [p].ParameterType, event_params [p].ParameterType);
						match = false;
						break;
					}
				}

				if (!match)
					continue;

				if (candidate != null)
					throw Parser.ParseException ("Multiple event handler candidates found for event {0}", Name);

				candidate = m;
			}

			if (candidate == null)
				throw Parser.ParseException ("Event handler not found for event {0}.", Name);

			d = Delegate.CreateDelegate (evnt.EventHandlerType, subscriber, candidate, false);
			if (d == null)
				throw Parser.ParseException ("Unable to create event delegate for event {0}.", Name);

			evnt.AddEventHandler (target, d);
		}
Ejemplo n.º 45
0
		private object ParseAttributeValue (XamlObjectElement element, XamlPropertySetter property)
		{
			object value = null;

			if (IsMarkupExpression (reader.Value))
				value = ParseAttributeMarkup (element, property);
			else {
				value = XamlTypeConverter.ConvertObject (this, element, property.Type, property.Converter, property.Name, reader.Value);
			}

			return value;
		}
Ejemplo n.º 46
0
		public override void SetValue (XamlObjectElement obj, object value)
		{
			if (value == null)
				throw Parser.ParseException ("Setting Name value to null.");

			string name = value as string;
			if (name == null)
				throw Parser.ParseException ("Unable to set Name property to type {1}.", value.GetType ());

			obj.X_Name = name;

			if (!target.SetNameOnScope (name, Parser.NameScope))
				throw Parser.ParseException ("Unable to set Name '{0}' on element '{1}'.", name, Element.Name);
		}
Ejemplo n.º 47
0
		private object ParseAttributeMarkup (XamlObjectElement element, XamlPropertySetter property)
		{
			MarkupExpressionParser parser = new SL4MarkupExpressionParser (element.Object, property.Name, this, element);

			string expression = reader.Value;
			object o = parser.ParseExpression (ref expression);
			return o;
		}
Ejemplo n.º 48
0
		XamlAttachedPropertySetter (XamlObjectElement element, Accessors accessors)
			: base (element, accessors.Name, accessors.ConverterCreator == null ? null : accessors.ConverterCreator ())
		{
			Accessors = accessors;
		}
Ejemplo n.º 49
0
		private void SetElementTemplateScopes (XamlObjectElement element)
		{
			// This whole thing is basically copied from xaml.cpp AddCreatedItem

			DependencyObject el_dob = element.Object as DependencyObject;
			if (el_dob == null)
				return;

			// When instantiating a template, some elements are created which are not explicitly
			// mentioned in the xaml. Therefore we need to keep walking up the tree until we find
			// the last element which we set a value for Control::IsTemplateItem and propagate
			// it from there.


			XamlElement instance = CurrentElement;

			while (instance != null) {

				XamlObjectElement oe = element as XamlObjectElement;
				if (oe == null) {
					instance = instance.Parent;
					continue;
				}

				DependencyObject dob = oe.Object as DependencyObject;
				if (dob == null) {
					instance = instance.Parent;
					continue;
				}

				if (dob.ReadLocalValue (Control.IsTemplateItemProperty) == null) {
					instance = instance.Parent;
					continue;
				}

				el_dob.SetValue (Control.IsTemplateItemProperty, dob.GetValue (Control.IsTemplateItemProperty));
				el_dob.TemplateOwner = dob.TemplateOwner;

				break;
			}
		
			if (instance == null) {
				el_dob.SetValue (Control.IsTemplateItemProperty, Context.IsExpandingTemplate);
				el_dob.TemplateOwner = Context.TemplateBindingSource;
			}

			if (el_dob.GetValue (Control.IsTemplateItemProperty) != null) {
				UserControl uc = el_dob as UserControl;
				if (uc != null) {
				        // I can't come up with a test to verify this fix. However, it does
				        // fix a crasher in olympics when trying to play a new video from
				        // the recommendations list after the curreont video finishes
					NameScope ns = NameScope.GetNameScope (uc);
					NameScope.SetNameScope (uc.Content, ns);
					NameScope.SetNameScope (uc.Resources, ns);
				}
				NameScope.SetNameScope (el_dob, NameScope);
			}
		}
Ejemplo n.º 50
0
		protected XamlPropertySetter (XamlObjectElement element, string name, TypeConverter converter)
		{
			Element = element;
			Name = name;
			Converter = converter;
		}
Ejemplo n.º 51
0
 public abstract void SetValue(XamlObjectElement obj, object value);