public void InitializeElement(object element, InitializeContext context)
 {
     foreach (IElementFactory elementFactory in elementsFactory)
     {
         Granular.Compatibility.Collection.DynamicAdd(element, elementFactory.CreateElement(context));
     }
 }
Exemple #2
0
            public KeyValuePair <object, object> CreateElement(InitializeContext context)
            {
                object element = valueFactory.CreateElement(context);

                object key = null;

                if (keyDirectiveFactory != null)
                {
                    key = keyDirectiveFactory.CreateElement(context);

                    if (keyProperty != null)
                    {
                        keyProperty.SetValue(element, key, context.ValueSource);
                    }
                }
                else if (deferredKeyFactory != null)
                {
                    key = deferredKeyFactory.CreateElement(context);
                }
                else
                {
                    key = keyProperty.GetValue(element);
                }

                return(new KeyValuePair <object, object>(key, element));
            }
        public void InitializeElement(object element, InitializeContext context)
        {
            context = context.CreateChildContext(element);

            if (!elementType.IsAssignableFrom(element.GetType()))
            {
                throw new Granular.Exception("Can't initialize element of type \"{0}\" as it's not a subclass of \"{1}\"", element.GetType().Name, elementType.Name);
            }

            if (element is ISupportInitialize)
            {
                ((ISupportInitialize)element).BeginInit();
            }

            if (element == context.Root && element is DependencyObject)
            {
                NameScope.SetNameScope((DependencyObject)element, context.NameScope);
            }

            if (element is FrameworkElement)
            {
                ((FrameworkElement)element).TemplatedParent = context.TemplatedParent;
            }

            foreach (IElementInitializer memberInitializer in memberInitializers)
            {
                memberInitializer.InitializeElement(element, context);
            }

            string name = nameDirectiveValue.DefaultIfNullOrEmpty(nameProperty != null ? (string)nameProperty.GetValue(element) : String.Empty);

            if (!nameDirectiveValue.IsNullOrEmpty() && nameProperty != null)
            {
                // name property exists, but the name directive was used, so update the property
                nameProperty.SetValue(element, name, context.ValueSource);
            }

            if (!name.IsNullOrEmpty())
            {
                context.NameScope.RegisterName(name, element);
            }

            if (contentInitializer != null)
            {
                contentInitializer.InitializeElement(element, context);
            }

            if (element == context.Root)
            {
                foreach (KeyValuePair <string, object> pair in context.NameScope)
                {
                    SetFieldValue(element, pair.Key, pair.Value);
                }
            }

            if (element is ISupportInitialize)
            {
                ((ISupportInitialize)element).EndInit();
            }
        }
Exemple #4
0
        public object CreateElement(InitializeContext context)
        {
            object target = Activator.CreateInstance(ElementType);

            elementInitializer.InitializeElement(target, context);
            return(target);
        }
 public object CreateElement(InitializeContext context)
 {
     return(new ValueProvider(() =>
     {
         InitializeContext localContext = new InitializeContext(null, null, new NameScope(context.NameScope), context.TemplatedParent, context.ValueSource);
         return elementFactory.CreateElement(localContext);
     }));
 }
        public void InitializeElement(object element, InitializeContext context)
        {
            foreach (KeyValueElementFactory keyElementFactory in keyElementFactories)
            {
                KeyValuePair <object, object> pair = keyElementFactory.CreateElement(context);

                Granular.Compatibility.Dictionary.DynamicAdd(element, pair.Key, pair.Value);
            }
        }
        public void InitializeElement(object element, InitializeContext context)
        {
            foreach (KeyElementFactory keyElementFactory in keyElementFactories)
            {
                KeyValuePair<object, object> pair = keyElementFactory.CreateElement(context);

                Granular.Compatibility.Dictionary.DynamicAdd(element, pair.Key, pair.Value);
            }
        }
        public FrameworkElement CreateElement(FrameworkElement templatedParent)
        {
            InitializeContext elementContext = new InitializeContext(null, context, new NameScope(context.NameScope), templatedParent, BaseValueSource.ParentTemplate);

            FrameworkElement element = elementFactory.CreateElement(elementContext) as FrameworkElement;

            NameScope.SetNameScope(element, elementContext.NameScope);

            return element;
        }
        private static object GetStaticResource(InitializeContext context, object resourceKey)
        {
            if (context == null)
            {
                throw new Granular.Exception("StaticResource \"{0}\" was not found", resourceKey);
            }

            object value;
            return context.Target is IResourceContainer && ((IResourceContainer)context.Target).TryGetResource(resourceKey, out value) ? value : GetStaticResource(context.ParentContext, resourceKey);
        }
        public InitializeContext(object target, InitializeContext parentContext, INameScope nameScope, FrameworkElement templatedParent, BaseValueSource valueSource)
        {
            this.Target = target;
            this.ParentContext = parentContext;

            this.NameScope = nameScope;
            this.TemplatedParent = templatedParent;
            this.ValueSource = valueSource;

            this.Root = parentContext != null && parentContext.Root != null ? parentContext.Root : Target;
        }
Exemple #11
0
        public InitializeContext(object target, InitializeContext parentContext, INameScope nameScope, FrameworkElement templatedParent, BaseValueSource valueSource)
        {
            this.Target        = target;
            this.ParentContext = parentContext;

            this.NameScope       = nameScope;
            this.TemplatedParent = templatedParent;
            this.ValueSource     = valueSource;

            this.Root = parentContext != null && parentContext.Root != null ? parentContext.Root : Target;
        }
            public void InitializeElement(object element, InitializeContext context)
            {
                object contentTarget = propertyAdapter.GetValue(element);

                if (contentTarget == null && propertyAdapter.PropertyType.GetDefaultConstructor() != null)
                {
                    contentTarget = Activator.CreateInstance(propertyAdapter.PropertyType);
                    propertyAdapter.SetValue(element, contentTarget, context.ValueSource);
                }

                propertyValueInitializer.InitializeElement(contentTarget, context);
            }
            public KeyValuePair <object, object> CreateElement(InitializeContext context)
            {
                object element = valueFactory.CreateElement(context);

                object key = keyDirectiveFactory != null?keyDirectiveFactory.CreateElement(context) : keyProperty.GetValue(element);

                if (keyDirectiveFactory != null && keyProperty != null)
                {
                    // key property exists, but the key directive was used, so update the property
                    keyProperty.SetValue(element, key, context.ValueSource);
                }

                return(new KeyValuePair <object, object>(key, element));
            }
Exemple #14
0
            public object CreateElement(InitializeContext context)
            {
                object value = null;

                return(new ValueProvider(() =>
                {
                    if (elementFactory == null)
                    {
                        elementFactory = ElementFactory.FromXamlElement(element, targetType);
                    }

                    if (value == null || !isShared)
                    {
                        value = elementFactory.CreateElement(context);
                    }

                    return value;
                }));
            }
 public void InitializeElement(object element, InitializeContext context)
 {
     eventAdapter.AddHandler(element, CreateEventHandler(eventAdapter.HandlerType, context.Root, eventHandlerName));
 }
 public object ProvideValue(InitializeContext context)
 {
     return new ResourceReferenceExpressionProvider(ResourceKey);
 }
Exemple #17
0
 public static InitializeContext SetNameScope(this InitializeContext context, INameScope nameScope)
 {
     return(new InitializeContext(context.Target, context.ParentContext, nameScope, context.TemplatedParent, context.ValueSource));
 }
 public FrameworkElementFactory(IElementFactory elementFactory, InitializeContext context)
 {
     this.elementFactory = elementFactory;
     this.context = context;
 }
Exemple #19
0
 public object CreateElement(InitializeContext context)
 {
     return value;
 }
Exemple #20
0
 public object CreateElement(InitializeContext context)
 {
     return TypeConverter.ConvertValue(valueFactory.CreateElement(context), ElementType, namespaces);
 }
Exemple #21
0
 public object CreateElement(InitializeContext context)
 {
     return(provider.GetValueKey(element));
 }
 public object ProvideValue(InitializeContext context)
 {
     return GetStaticResource(context, ResourceKey);
 }
Exemple #23
0
 public static InitializeContext CreateChildContext(this InitializeContext context, object child)
 {
     return(new InitializeContext(child, context, context.NameScope, context.TemplatedParent, context.ValueSource));
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     foreach (IElementFactory elementFactory in elementsFactory)
     {
         Granular.Compatibility.Collection.DynamicAdd(element, elementFactory.CreateElement(context));
     }
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     propertyAdapter.SetValue(element, propertyValueFactory.CreateElement(context), context.ValueSource);
 }
 public object CreateElement(InitializeContext context)
 {
     return new ValueProvider(() =>
     {
         InitializeContext localContext = new InitializeContext(null, null, new NameScope(context.NameScope), context.TemplatedParent, context.ValueSource);
         return elementFactory.CreateElement(localContext);
     });
 }
Exemple #27
0
 public object CreateElement(InitializeContext context)
 {
     return ((IMarkupExtension)valueFactory.CreateElement(context)).ProvideValue(context);
 }
        public void InitializeElement(object element, InitializeContext context)
        {
            context = context.CreateChildContext(element);

            if (!elementType.IsAssignableFrom(element.GetType()))
            {
                throw new Granular.Exception("Can't initialize element of type \"{0}\" as it's not a subclass of \"{1}\"", element.GetType().Name, elementType.Name);
            }

            if (element is ISupportInitialize)
            {
                ((ISupportInitialize)element).BeginInit();
            }

            if (element == context.Root && element is DependencyObject)
            {
                NameScope.SetNameScope((DependencyObject)element, context.NameScope);
            }

            if (element is FrameworkElement)
            {
                ((FrameworkElement)element).TemplatedParent = context.TemplatedParent;
            }

            foreach (IElementInitializer memberInitializer in memberInitializers)
            {
                memberInitializer.InitializeElement(element, context);
            }

            string name = nameDirectiveValue.DefaultIfNullOrEmpty(nameProperty != null ? (string)nameProperty.GetValue(element) : String.Empty);

            if (!nameDirectiveValue.IsNullOrEmpty() && nameProperty != null)
            {
                // name property exists, but the name directive was used, so update the property
                nameProperty.SetValue(element, name, context.ValueSource);
            }

            if (!name.IsNullOrEmpty())
            {
                context.NameScope.RegisterName(name, element);
            }

            if (contentInitializer != null)
            {
                contentInitializer.InitializeElement(element, context);
            }

            if (element == context.Root)
            {
                foreach (KeyValuePair<string, object> pair in context.NameScope)
                {
                    SetFieldValue(element, pair.Key, pair.Value);
                }
            }

            if (element is ISupportInitialize)
            {
                ((ISupportInitialize)element).EndInit();
            }
        }
Exemple #29
0
 public object CreateElement(InitializeContext context)
 {
     object target = Activator.CreateInstance(ElementType);
     elementInitializer.InitializeElement(target, context);
     return target;
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     propertyAdapter.SetValue(element, propertyValueFactory.CreateElement(context), context.ValueSource);
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     propertyAdapter.SetValue(element, new FrameworkElementFactory(elementFactory, context), context.ValueSource);
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     propertyAdapter.SetValue(element, new FrameworkElementFactory(elementFactory, context), context.ValueSource);
 }
Exemple #33
0
 public object CreateElement(InitializeContext context)
 {
     return(typeConverter.ConvertFrom(namespaces, sourceUri, valueFactory.CreateElement(context)));
 }
Exemple #34
0
 public static InitializeContext SetTarget(this InitializeContext context, object target)
 {
     return(new InitializeContext(target, context.ParentContext, context.NameScope, context.TemplatedParent, context.ValueSource));
 }
            public KeyValuePair<object, object> CreateElement(InitializeContext context)
            {
                object element = valueFactory.CreateElement(context);

                object key = keyDirectiveFactory != null ? keyDirectiveFactory.CreateElement(context) : keyProperty.GetValue(element);

                if (keyDirectiveFactory != null && keyProperty != null)
                {
                    // key property exists, but the key directive was used, so update the property
                    keyProperty.SetValue(element, key, context.ValueSource);
                }

                return new KeyValuePair<object, object>(key, element);
            }
Exemple #36
0
 public object CreateElement(InitializeContext context)
 {
     return(value);
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     eventAdapter.AddHandler(element, CreateEventHandler(eventAdapter.HandlerType, context.Root, eventHandlerName));
 }
Exemple #38
0
 public object CreateElement(InitializeContext context)
 {
     return(((IMarkupExtension)valueFactory.CreateElement(context)).ProvideValue(context));
 }
 public void InitializeElement(object element, InitializeContext context)
 {
     //
 }
Exemple #40
0
 public object ProvideValue(InitializeContext context)
 {
     return(Type);
 }
            public void InitializeElement(object element, InitializeContext context)
            {
                object contentTarget = propertyAdapter.GetValue(element);

                if (contentTarget == null && propertyAdapter.PropertyType.GetDefaultConstructor() != null)
                {
                    contentTarget = Activator.CreateInstance(propertyAdapter.PropertyType);
                    propertyAdapter.SetValue(element, contentTarget, context.ValueSource);
                }

                propertyValueInitializer.InitializeElement(contentTarget, context);
            }
 public void InitializeElement(object element, InitializeContext context)
 {
     //
 }
Exemple #43
0
 public object ProvideValue(InitializeContext context)
 {
     return Type;
 }
 public object CreateElement(InitializeContext context)
 {
     return(TypeConverter.ConvertValue(valueFactory.CreateElement(context), ElementType, namespaces));
 }