/// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var eventHandlerName = ProcessPrecomputedValue<String>(value, context);
            if (eventHandlerName == null)
                throw new UvmlException(PresentationStrings.InvalidEventHandler.Format(eventInfo.Name, "(null)"));

            var eventHandlerDelegate = CreateEventHandlerDelegate(eventHandlerName, eventInfo.EventHandlerType, context);
            eventInfo.AddEventHandler(instance, eventHandlerDelegate);
        }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;
            if (dobj == null)
                return;

            var processedValue = ProcessPrecomputedValue<Object>(value, context);
            dpropSetter.Invoke(instance, new Object[] { dpropID, processedValue });
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
        {
            if (String.Equals(Literal, "{{null}}", StringComparison.Ordinal))
                return Type.IsValueType ? Activator.CreateInstance(Type) : null;

            if (typeof(UIElement).IsAssignableFrom(Type))
            {
                return new UvmlElementReference(Literal);
            }

            return ObjectResolver.FromString(Literal, Type, Culture);
        }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var uiElement = instance as UIElement;
            if (uiElement == null)
                return;

            var eventHandlerName = ProcessPrecomputedValue<String>(value, context);
            if (eventHandlerName == null)
                throw new UvmlException(PresentationStrings.InvalidEventHandler.Format(revtID.Name, "(null)"));

            var eventHandlerDelegate = CreateEventHandlerDelegate(eventHandlerName, revtID.DelegateType, context);
            uiElement.AddHandler(revtID, eventHandlerDelegate);
        }
Exemplo n.º 5
0
        /// <inheritdoc/>
        public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
        {
            if (String.Equals(Literal, "{{null}}", StringComparison.Ordinal))
            {
                return(Type.IsValueType ? Activator.CreateInstance(Type) : null);
            }

            if (typeof(IInputElement).IsAssignableFrom(Type))
            {
                return(new UvmlElementReference(Literal));
            }

            return(ObjectResolver.FromString(Literal, Type, Culture));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new collection instance of the specified type.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="instance">The object instance which is being mutated.</param>
        /// <param name="context">The current instantiation context.</param>
        /// <param name="type">The type of collection to create.</param>
        /// <param name="collection">The collection which was created.</param>
        /// <returns><see langword="true"/> if the collection was able to be created;
        /// otherwise, <see langword="false"/>.</returns>
        protected Boolean CreateCollectionOfType(UltravioletContext uv,
                                                 Object instance, UvmlInstantiationContext context, Type type, out Object collection)
        {
            var ctor = type.GetConstructor(Type.EmptyTypes);

            if (ctor == null)
            {
                collection = null;
                return(false);
            }

            collection = ctor.Invoke(null);
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a handler delegate for an event.
        /// </summary>
        /// <param name="name">The name of the method which will handle the event.</param>
        /// <param name="type">The type of delegate which handles the event.</param>
        /// <param name="context">The current instantiation context.</param>
        /// <returns>The delegate which was created to handle the event.</returns>
        protected static Delegate CreateEventHandlerDelegate(String name, Type type, UvmlInstantiationContext context)
        {
            var dataSource = context.DataSource;
            var dataSourceType = context.DataSourceType;

            var templatedParent = context.TemplatedParent as UIElement;
            if (templatedParent != null)
            {
                dataSource = templatedParent;
                PresentationFoundation.Instance.ComponentTemplates.Get(templatedParent, out dataSourceType);
            }

            return BindingExpressions.CreateBoundEventDelegate(dataSource, dataSourceType, type, name);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a handler delegate for an event.
        /// </summary>
        /// <param name="name">The name of the method which will handle the event.</param>
        /// <param name="type">The type of delegate which handles the event.</param>
        /// <param name="context">The current instantiation context.</param>
        /// <returns>The delegate which was created to handle the event.</returns>
        protected static Delegate CreateEventHandlerDelegate(String name, Type type, UvmlInstantiationContext context)
        {
            var dataSource     = context.DataSource;
            var dataSourceType = context.DataSourceType;

            var templatedParent = context.TemplatedParent as UIElement;

            if (templatedParent != null)
            {
                dataSource = templatedParent;
                PresentationFoundation.Instance.ComponentTemplates.Get(templatedParent, out dataSourceType);
            }

            return(BindingExpressions.CreateBoundEventDelegate(dataSource, dataSourceType, type, name));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads the content of the template as an instance of an object and returns the root element of the content.
        /// </summary>
        /// <param name="dataSource">The object's data source.</param>
        /// <param name="dataSourceType">The object's data source type.</param>
        /// <returns>The root element of the content.</returns>
        public DependencyObject LoadContent(Object dataSource, Type dataSourceType)
        {
            var uv = UltravioletContext.DemandCurrent();
            var namescope = default(Namescope);
            var wrapper = CreateDataSourceWrapper(dataSource, dataSourceType, out namescope);
            var context = new UvmlInstantiationContext(uv, null, wrapper, wrapper?.GetType(), namescope);
            var dobj = (DependencyObject)((UvmlTemplateInstance)template.Instantiate(uv, context)).Finalize();

            var element = dobj as FrameworkElement;
            if (element != null)
                element.TemplatedNamescope = namescope;

            if (dataSource != null)
                namescope.PopulateFieldsFromRegisteredElements(dataSource);

            return dobj;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="UIElement"/> class.
        /// </summary>
        private void InitializeElement(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var uiElement = instance as UIElement;

            if (uiElement == null)
            {
                return;
            }

            if (uiElement != null && classes != null)
            {
                foreach (var className in classes)
                {
                    uiElement.Classes.Add(className);
                }
            }
        }
Exemplo n.º 11
0
        /// <inheritdoc/>
        public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
        {
            var instance = instantiator(uv, name);

            if (instance == null)
            {
                throw new NullReferenceException(nameof(instance));
            }

            InitializeFrameworkElement(uv, instance, context);
            InitializeElement(uv, instance, context);
            InitializeDependencyObject(uv, instance, context);

            var mutatorsWithValues =
                (from mutator in mutators
                 select new
            {
                Mutator = mutator,
                Value = mutator.InstantiateValue(uv, instance, context)
            }).ToArray();

            return(new UvmlTemplateInstance(instance, () =>
            {
                foreach (var mutator in mutatorsWithValues)
                {
                    mutator.Mutator.Mutate(uv, instance, mutator.Value, context);
                }

                InitializeContentPresenter(uv, instance, context);

                if (IsItemsPanelForTemplatedParent)
                {
                    var itemsControl = context.TemplatedParent as ItemsControl;
                    if (itemsControl != null)
                    {
                        itemsControl.ItemsPanelElement = instance as Panel;
                    }
                }

                var fe = instance as FrameworkElement;
                if (fe != null)
                {
                    fe.EndInit();
                }
            }));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Processes the specified value for use by a mutator.
        /// </summary>
        /// <typeparam name="T">The type of value which is expected.</typeparam>
        /// <param name="value">The value to process.</param>
        /// <param name="context">The current instantiation context.</param>
        /// <returns>The value after it has been converted to the expected type.</returns>
        protected static T ProcessPrecomputedValue <T>(Object value, UvmlInstantiationContext context)
        {
            var templateInstance = value as UvmlTemplateInstance;

            if (templateInstance != null)
            {
                return((T)templateInstance.Finalize());
            }

            var elementReference = value as UvmlElementReference;

            if (elementReference != null)
            {
                return((T)elementReference.GetReferencedElement(context.Namescope));
            }

            return((T)value);
        }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;
            if (dobj == null)
                return;

            var expression = ProcessPrecomputedValue<String>(value, context);
            if (expression == null)
                throw new UvmlException(PresentationStrings.InvalidBindingExpression.Format("(null)"));

            var compiled = context.GetCompiledBindingExpression(dpropID.PropertyType, expression);
            if (compiled == null)
                throw new UvmlException(PresentationStrings.CompiledExpressionNotFound.Format(expression));

            var fmtString = BindingExpressions.GetBindingFormatStringPart(expression);
            if (fmtString != null)
            {
                dobj.BindValue(dpropID, context.DataSourceType, "{{" + compiled.Name + "}}[" + fmtString + "]");
            }
            else
            {
                dobj.BindValue(dpropID, context.DataSourceType, "{{" + compiled.Name + "}}");
            }
        }
 /// <inheritdoc/>
 public override Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     return eventHandler.Instantiate(uv, context);
 }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;

            if (dobj == null)
            {
                return;
            }

            var expression = ProcessPrecomputedValue <String>(value, context);

            if (expression == null)
            {
                throw new UvmlException(PresentationStrings.InvalidBindingExpression.Format("(null)"));
            }

            var compiled = context.GetCompiledBindingExpression(dpropID.PropertyType, expression);

            if (compiled == null)
            {
                throw new UvmlException(PresentationStrings.CompiledExpressionNotFound.Format(expression));
            }

            var fmtString = BindingExpressions.GetBindingFormatStringPart(expression);

            if (fmtString != null)
            {
                dobj.BindValue(dpropID, context.DataSourceType, "{{" + compiled.Name + "}}[" + fmtString + "]");
            }
            else
            {
                dobj.BindValue(dpropID, context.DataSourceType, "{{" + compiled.Name + "}}");
            }
        }
Exemplo n.º 16
0
 /// <inheritdoc/>
 protected override Boolean CreateCollection(UltravioletContext uv, Object instance, UvmlInstantiationContext context, out Object collection)
 {
     return(CreateCollectionOfType(uv, instance, context, dpropID.PropertyType, out collection));
 }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var processedValue = ProcessPrecomputedValue <Object>(value, context);

            propertyInfo.SetValue(instance, processedValue, null);
        }
 /// <inheritdoc/>
 public override Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     return propertyValue.Instantiate(uv, context);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="ContentPresenter"/> class.
        /// </summary>
        private void InitializeContentPresenter(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var contentPresenter = instance as ContentPresenter;

            if (contentPresenter == null)
            {
                return;
            }

            if (contentPresenter.HasDefinedValue(ContentPresenter.ContentProperty) || contentPresenter.TemplatedParent == null)
            {
                return;
            }

            var alias = contentPresenter.ContentSource ?? "Content";

            if (alias == String.Empty)
            {
                return;
            }

            var templateType        = contentPresenter.TemplatedParent.GetType();
            var templateWrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType);
            var templateWrapperType = uv.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(templateWrapperName);

            var dpAliasedContent = DependencyProperty.FindByName(alias, templateType);

            if (dpAliasedContent != null)
            {
                contentPresenter.BindValue(ContentPresenter.ContentProperty, templateWrapperType,
                                           "{{" + dpAliasedContent.Name + "}}");
            }

            if (!contentPresenter.HasDefinedValue(ContentPresenter.ContentStringFormatProperty))
            {
                var dpAliasedContentStringFormat = DependencyProperty.FindByName(alias + "StringFormat", templateType);
                if (dpAliasedContentStringFormat != null)
                {
                    contentPresenter.BindValue(ContentPresenter.ContentStringFormatProperty, templateWrapperType,
                                               "{{" + dpAliasedContentStringFormat.Name + "}}");
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="UIElement"/> class.
        /// </summary>
        private void InitializeElement(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var uiElement = instance as UIElement;
            if (uiElement == null)
                return;

            if (uiElement != null && classes != null)
            {
                foreach (var className in classes)
                    uiElement.Classes.Add(className);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Instantiates the value represented by the node.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="context">The instantiation context for this node.</param>
 /// <returns>The object which was instantiated by the node.</returns>
 public abstract Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context);
Exemplo n.º 22
0
        /// <inheritdoc/>
        public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
        {
            var instance = instantiator(uv, name);
            if (instance == null)
                throw new NullReferenceException(nameof(instance));

            InitializeFrameworkElement(uv, instance, context);
            InitializeElement(uv, instance, context);
            InitializeDependencyObject(uv, instance, context);

            var mutatorsWithValues =
                (from mutator in mutators
                 select new
                 {
                     Mutator = mutator,
                     Value = mutator.InstantiateValue(uv, instance, context)
                 }).ToArray();

            return new UvmlTemplateInstance(instance, () =>
            {
                foreach (var mutator in mutatorsWithValues)
                    mutator.Mutator.Mutate(uv, instance, mutator.Value, context);

                InitializeContentPresenter(uv, instance, context);

                if (IsItemsPanelForTemplatedParent)
                {
                    var itemsControl = context.TemplatedParent as ItemsControl;
                    if (itemsControl != null)
                        itemsControl.ItemsPanelElement = instance as Panel;
                }

                var fe = instance as FrameworkElement;
                if (fe != null)
                    fe.EndInit();
            });
        }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var items = ProcessPrecomputedValue<List<Object>>(value, context);
            if (items == null)
                throw new ArgumentException(nameof(value));

            var propname = default(String);
            var collection = default(Object);
            if (!GetCollection(instance, out collection, out propname))
                throw new UvmlException(PresentationStrings.PropertyHasNoGetter.Format(propname));

            if (collection == null)
            {
                if (!CreateCollection(uv, instance, context, out collection))
                    throw new UvmlException(PresentationStrings.CollectionCannotBeCreated.Format(propname));

                if (!SetCollection(instance, collection))
                    throw new UvmlException(PresentationStrings.PropertyHasNoSetter.Format(propname));
            }

            var listType = collection.GetType();
            var listItemType = GetCollectionItemType(listType);
            if (listItemType == null)
                throw new UvmlException(PresentationStrings.CollectionTypeNotSupported.Format(listType));

            var listClearMethod = listType.GetMethod("Clear",
                BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null);
            if (listClearMethod == null)
                throw new UvmlException(PresentationStrings.CollectionCannotBeCleared.Format(listType.Name));

            listClearMethod.Invoke(collection, null);

            var listAddRangeMethod = listType.GetMethod("AddRange",
                BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(IEnumerable<>).MakeGenericType(listItemType) }, null);
            if (listAddRangeMethod != null)
            {
                var itemInstances = Array.CreateInstance(listItemType, items.Count);
                for (int i = 0; i < items.Count; i++)
                {
                    var item = ProcessPrecomputedValue<Object>(items[i], context);
                    itemInstances.SetValue(item, i);
                }
                listAddRangeMethod.Invoke(collection, new[] { itemInstances });
            }
            else
            {
                var listAddMethodParameters = new Object[] { null };
                var listAddMethod = listType.GetMethod("Add",
                    BindingFlags.Public | BindingFlags.Instance, null, new[] { listItemType }, null);
                if (listAddMethod != null)
                {
                    foreach (var item in items)
                    {
                        listAddMethodParameters[0] = ProcessPrecomputedValue<Object>(item, context);
                        listAddMethod.Invoke(collection, listAddMethodParameters);
                    }
                }
                else
                {
                    throw new UvmlException(PresentationStrings.CollectionHasNoAddMethod.Format(listType.Name));
                }
            }
        }
 /// <inheritdoc/>
 public override Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     return items.Select(x => x.Instantiate(uv, context)).ToList();
 }
        /// <summary>
        /// Creates a new collection instance of the specified type.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="instance">The object instance which is being mutated.</param>
        /// <param name="context">The current instantiation context.</param>
        /// <param name="type">The type of collection to create.</param>
        /// <param name="collection">The collection which was created.</param>
        /// <returns><see langword="true"/> if the collection was able to be created;
        /// otherwise, <see langword="false"/>.</returns>
        protected Boolean CreateCollectionOfType(UltravioletContext uv,
            Object instance, UvmlInstantiationContext context, Type type, out Object collection)
        {
            var ctor = type.GetConstructor(Type.EmptyTypes);
            if (ctor == null)
            {
                collection = null;
                return false;
            }

            collection = ctor.Invoke(null);
            return true;
        }
 /// <summary>
 /// Creates a new collection instance for the mutated property.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="instance">The object instance which is being mutated.</param>
 /// <param name="context">The current instantiation context.</param>
 /// <param name="collection">The collection which was created.</param>
 /// <returns><see langword="true"/> if the collection was able to be created;
 /// otherwise, <see langword="false"/>.</returns>
 protected abstract Boolean CreateCollection(UltravioletContext uv,
     Object instance, UvmlInstantiationContext context, out Object collection);
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;

            if (dobj == null)
            {
                return;
            }

            var processedValue = ProcessPrecomputedValue <Object>(value, context);

            dpropSetter.Invoke(instance, new Object[] { dpropID, processedValue });
        }
Exemplo n.º 28
0
 /// <inheritdoc/>
 protected override Boolean CreateCollection(UltravioletContext uv, Object instance, UvmlInstantiationContext context, out Object collection)
 {
     collection = null;
     return false;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Instantiates the value associated with this mutation.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="instance">The object instance to mutate.</param>
 /// <param name="context">The current instantiation context.</param>
 /// <returns>The value which was instantiated.</returns>
 public abstract Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context);
Exemplo n.º 30
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="DependencyObject"/> class.
        /// </summary>
        private void InitializeDependencyObject(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;

            if (dobj == null)
            {
                return;
            }

            dobj.DeclarativeDataSource = context.DataSource;
        }
Exemplo n.º 31
0
 /// <summary>
 /// Applies the mutation to the specified object instance using the specified precomputed value.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="instance">The object instance to mutate.</param>
 /// <param name="value">The precomputed value to apply with the mutation.</param>
 /// <param name="context">The current instantiation context.</param>
 public abstract void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context);
Exemplo n.º 32
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="DependencyObject"/> class.
        /// </summary>
        private void InitializeDependencyObject(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var dobj = instance as DependencyObject;
            if (dobj == null)
                return;

            dobj.DeclarativeDataSource = context.DataSource;
        }
Exemplo n.º 33
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="FrameworkElement"/> class.
        /// </summary>
        private void InitializeFrameworkElement(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var frameworkElement = instance as FrameworkElement;
            if (frameworkElement == null)
                return;

            context.Namescope.RegisterElement(frameworkElement);

            frameworkElement.BeginInit();
            frameworkElement.TemplatedParent = context.TemplatedParent as DependencyObject;
        }
 /// <inheritdoc/>
 public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
 {
     var processedValue = ProcessPrecomputedValue<Object>(value, context);
     propertyInfo.SetValue(instance, processedValue, null);
 }
Exemplo n.º 35
0
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var value = InstantiateValue(uv, instance, context);

            Mutate(uv, instance, value, context);
        }
Exemplo n.º 36
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="ContentPresenter"/> class.
        /// </summary>
        private void InitializeContentPresenter(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var contentPresenter = instance as ContentPresenter;
            if (contentPresenter == null)
                return;

            if (contentPresenter.HasDefinedValue(ContentPresenter.ContentProperty) || contentPresenter.TemplatedParent == null)
                return;

            var alias = contentPresenter.ContentSource ?? "Content";
            if (alias == String.Empty)
                return;

            var templateType = contentPresenter.TemplatedParent.GetType();
            var templateWrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType);
            var templateWrapperType = uv.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(templateWrapperName);

            var dpAliasedContent = DependencyProperty.FindByName(alias, templateType);
            if (dpAliasedContent != null)
            {
                contentPresenter.BindValue(ContentPresenter.ContentProperty, templateWrapperType,
                    "{{" + dpAliasedContent.Name + "}}");
            }

            if (!contentPresenter.HasDefinedValue(ContentPresenter.ContentStringFormatProperty))
            {
                var dpAliasedContentStringFormat = DependencyProperty.FindByName(alias + "StringFormat", templateType);
                if (dpAliasedContentStringFormat != null)
                {
                    contentPresenter.BindValue(ContentPresenter.ContentStringFormatProperty, templateWrapperType,
                        "{{" + dpAliasedContentStringFormat.Name + "}}");
                }
            }
        }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var eventHandlerName = ProcessPrecomputedValue <String>(value, context);

            if (eventHandlerName == null)
            {
                throw new UvmlException(PresentationStrings.InvalidEventHandler.Format(eventInfo.Name, "(null)"));
            }

            var eventHandlerDelegate = CreateEventHandlerDelegate(eventHandlerName, eventInfo.EventHandlerType, context);

            eventInfo.AddEventHandler(instance, eventHandlerDelegate);
        }
 /// <inheritdoc/>
 public override Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     return(dpropValue.Instantiate(uv, context));
 }
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var uiElement = instance as UIElement;

            if (uiElement == null)
            {
                return;
            }

            var eventHandlerName = ProcessPrecomputedValue <String>(value, context);

            if (eventHandlerName == null)
            {
                throw new UvmlException(PresentationStrings.InvalidEventHandler.Format(revtID.Name, "(null)"));
            }

            var eventHandlerDelegate = CreateEventHandlerDelegate(eventHandlerName, revtID.DelegateType, context);

            uiElement.AddHandler(revtID, eventHandlerDelegate);
        }
 /// <inheritdoc/>
 protected override Boolean CreateCollection(UltravioletContext uv, Object instance, UvmlInstantiationContext context, out Object collection)
 {
     return CreateCollectionOfType(uv, instance, context, dpropID.PropertyType, out collection);
 }
Exemplo n.º 41
0
 /// <summary>
 /// Instantiates the value represented by the node.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="context">The instantiation context for this node.</param>
 /// <returns>The object which was instantiated by the node.</returns>
 public abstract Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context);
 /// <inheritdoc/>
 public override void Mutate(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     var value = InstantiateValue(uv, instance, context);
     Mutate(uv, instance, value, context);
 }
Exemplo n.º 43
0
        /// <summary>
        /// Performs initialization required by instances of the <see cref="FrameworkElement"/> class.
        /// </summary>
        private void InitializeFrameworkElement(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
        {
            var frameworkElement = instance as FrameworkElement;

            if (frameworkElement == null)
            {
                return;
            }

            context.Namescope.RegisterElement(frameworkElement);

            frameworkElement.BeginInit();
            frameworkElement.TemplatedParent = context.TemplatedParent as DependencyObject;
        }
Exemplo n.º 44
0
 /// <summary>
 /// Creates a new collection instance for the mutated property.
 /// </summary>
 /// <param name="uv">The Ultraviolet context.</param>
 /// <param name="instance">The object instance which is being mutated.</param>
 /// <param name="context">The current instantiation context.</param>
 /// <param name="collection">The collection which was created.</param>
 /// <returns><see langword="true"/> if the collection was able to be created;
 /// otherwise, <see langword="false"/>.</returns>
 protected abstract Boolean CreateCollection(UltravioletContext uv,
                                             Object instance, UvmlInstantiationContext context, out Object collection);
Exemplo n.º 45
0
 /// <inheritdoc/>
 protected override Boolean CreateCollection(UltravioletContext uv, Object instance, UvmlInstantiationContext context, out Object collection)
 {
     collection = null;
     return(false);
 }
Exemplo n.º 46
0
 /// <inheritdoc/>
 public override Object InstantiateValue(UltravioletContext uv, Object instance, UvmlInstantiationContext context)
 {
     return(items.Select(x => x.Instantiate(uv, context)).ToList());
 }
Exemplo n.º 47
0
 /// <inheritdoc/>
 public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
 {
     return(Template);
 }
Exemplo n.º 48
0
        /// <inheritdoc/>
        public override void Mutate(UltravioletContext uv, Object instance, Object value, UvmlInstantiationContext context)
        {
            var items = ProcessPrecomputedValue <List <Object> >(value, context);

            if (items == null)
            {
                throw new ArgumentException(nameof(value));
            }

            var propname   = default(String);
            var collection = default(Object);

            if (!GetCollection(instance, out collection, out propname))
            {
                throw new UvmlException(PresentationStrings.PropertyHasNoGetter.Format(propname));
            }

            if (collection == null)
            {
                if (!CreateCollection(uv, instance, context, out collection))
                {
                    throw new UvmlException(PresentationStrings.CollectionCannotBeCreated.Format(propname));
                }

                if (!SetCollection(instance, collection))
                {
                    throw new UvmlException(PresentationStrings.PropertyHasNoSetter.Format(propname));
                }
            }

            var listType     = collection.GetType();
            var listItemType = GetCollectionItemType(listType);

            if (listItemType == null)
            {
                throw new UvmlException(PresentationStrings.CollectionTypeNotSupported.Format(listType));
            }

            var listClearMethod = listType.GetMethod("Clear",
                                                     BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null);

            if (listClearMethod == null)
            {
                throw new UvmlException(PresentationStrings.CollectionCannotBeCleared.Format(listType.Name));
            }

            listClearMethod.Invoke(collection, null);

            var listAddRangeMethod = listType.GetMethod("AddRange",
                                                        BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(IEnumerable <>).MakeGenericType(listItemType) }, null);

            if (listAddRangeMethod != null)
            {
                var itemInstances = Array.CreateInstance(listItemType, items.Count);
                for (int i = 0; i < items.Count; i++)
                {
                    var item = ProcessPrecomputedValue <Object>(items[i], context);
                    itemInstances.SetValue(item, i);
                }
                listAddRangeMethod.Invoke(collection, new[] { itemInstances });
            }
            else
            {
                var listAddMethodParameters = new Object[] { null };
                var listAddMethod           = listType.GetMethod("Add",
                                                                 BindingFlags.Public | BindingFlags.Instance, null, new[] { listItemType }, null);
                if (listAddMethod != null)
                {
                    foreach (var item in items)
                    {
                        listAddMethodParameters[0] = ProcessPrecomputedValue <Object>(item, context);
                        listAddMethod.Invoke(collection, listAddMethodParameters);
                    }
                }
                else
                {
                    throw new UvmlException(PresentationStrings.CollectionHasNoAddMethod.Format(listType.Name));
                }
            }
        }
Exemplo n.º 49
0
 /// <inheritdoc/>
 public override Object Instantiate(UltravioletContext uv, UvmlInstantiationContext context)
 {
     return Template;
 }