public void InitializeElement(object element, InitializeContext context)
 {
     foreach (IElementFactory elementFactory in elementsFactory)
     {
         Granular.Compatibility.Collection.DynamicAdd(element, elementFactory.CreateElement(context));
     }
 }
Beispiel #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();
            }
        }
Beispiel #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);
            }
        }
Beispiel #7
0
        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);
        }
Beispiel #10
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;
        }
Beispiel #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));
            }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #19
0
 public object CreateElement(InitializeContext context)
 {
     return value;
 }
Beispiel #20
0
 public object CreateElement(InitializeContext context)
 {
     return TypeConverter.ConvertValue(valueFactory.CreateElement(context), ElementType, namespaces);
 }
Beispiel #21
0
 public object CreateElement(InitializeContext context)
 {
     return(provider.GetValueKey(element));
 }
 public object ProvideValue(InitializeContext context)
 {
     return GetStaticResource(context, ResourceKey);
 }
Beispiel #23
0
 public static InitializeContext CreateChildContext(this InitializeContext context, object child)
 {
     return(new InitializeContext(child, context, context.NameScope, context.TemplatedParent, context.ValueSource));
 }
Beispiel #24
0
 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);
 }
Beispiel #26
0
 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);
     });
 }
Beispiel #27
0
 public object CreateElement(InitializeContext context)
 {
     return ((IMarkupExtension)valueFactory.CreateElement(context)).ProvideValue(context);
 }
Beispiel #28
0
        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();
            }
        }
Beispiel #29
0
 public object CreateElement(InitializeContext context)
 {
     object target = Activator.CreateInstance(ElementType);
     elementInitializer.InitializeElement(target, context);
     return target;
 }
Beispiel #30
0
 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);
 }
Beispiel #32
0
 public void InitializeElement(object element, InitializeContext context)
 {
     propertyAdapter.SetValue(element, new FrameworkElementFactory(elementFactory, context), context.ValueSource);
 }
Beispiel #33
0
 public object CreateElement(InitializeContext context)
 {
     return(typeConverter.ConvertFrom(namespaces, sourceUri, valueFactory.CreateElement(context)));
 }
Beispiel #34
0
 public static InitializeContext SetTarget(this InitializeContext context, object target)
 {
     return(new InitializeContext(target, context.ParentContext, context.NameScope, context.TemplatedParent, context.ValueSource));
 }
Beispiel #35
0
            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);
            }
Beispiel #36
0
 public object CreateElement(InitializeContext context)
 {
     return(value);
 }
Beispiel #37
0
 public void InitializeElement(object element, InitializeContext context)
 {
     eventAdapter.AddHandler(element, CreateEventHandler(eventAdapter.HandlerType, context.Root, eventHandlerName));
 }
Beispiel #38
0
 public object CreateElement(InitializeContext context)
 {
     return(((IMarkupExtension)valueFactory.CreateElement(context)).ProvideValue(context));
 }
Beispiel #39
0
 public void InitializeElement(object element, InitializeContext context)
 {
     //
 }
Beispiel #40
0
 public object ProvideValue(InitializeContext context)
 {
     return(Type);
 }
Beispiel #41
0
            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)
 {
     //
 }
Beispiel #43
0
 public object ProvideValue(InitializeContext context)
 {
     return Type;
 }
Beispiel #44
0
 public object CreateElement(InitializeContext context)
 {
     return(TypeConverter.ConvertValue(valueFactory.CreateElement(context), ElementType, namespaces));
 }