예제 #1
0
        /// <summary>
        /// Disposes and detaches behaviors attached to the specified element and optionally
        /// to contained elements.
        /// </summary>
        /// <param name="element">The element to detach behaviors from.</param>
        /// <param name="recursive">Whether to recursively detach behaviors from contained elements.</param>
        public static void DisposeBehaviors(Element element, bool recursive)
        {
            Debug.Assert(element != null);

            // TODO: Fix Script.Web
            if ((bool)Type.InvokeMethod(element, "hasAttribute", Behavior.BehaviorsAttribute)) {
                DetachBehaviors(element);
            }

            if (recursive) {
                ElementCollection elements = element.QuerySelectorAll(Behavior.BehaviorsSelector);
                int matchingElements = elements.Length;

                if (matchingElements != 0) {
                    for (int i = 0; i < matchingElements; i++) {
                        DetachBehaviors(elements[i]);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Deactivates the specified element and its children by disposing any
        /// behaviors or binding instances attached to the elements.
        /// </summary>
        /// <param name="element">The element to deactivate.</param>
        /// <param name="contentOnly">Whether the element should be deactivated, or only its contained content.</param>
        public void DeactivateFragment(Element element, bool contentOnly)
        {
            Debug.Assert(element != null);

            // Detach behaviors associated with the element and the contained elements.
            if ((contentOnly == false) && element.HasAttribute(Application.BehaviorsAttribute)) {
                DetachBehaviors(element);
            }

            ElementCollection elements = element.QuerySelectorAll(Application.BehaviorsSelector);
            int matchingElements = elements.Length;

            if (matchingElements != 0) {
                for (int i = 0; i < matchingElements; i++) {
                    DetachBehaviors(elements[i]);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Attaches behaviors associated declaratively with the specified element and optionally
        /// to contained elements.
        /// </summary>
        /// <param name="element">The element to attach behaviors to.</param>
        /// <param name="recursive">Whether to recursively attach behaviors from contained elements.</param>
        public static void SetupBehaviors(Element element, bool recursive)
        {
            Debug.Assert(element != null);

            if (element.HasAttribute(Behavior.BehaviorsAttribute)) {
                AttachBehaviors(element);
            }

            if (recursive) {
                ElementCollection elements = element.QuerySelectorAll(Behavior.BehaviorsSelector);
                int matchingElements = elements.Length;

                if (matchingElements != 0) {
                    for (int i = 0; i < matchingElements; i++) {
                        AttachBehaviors(elements[i]);
                    }
                }
            }
        }
예제 #4
0
        public void ActivateFragment(Element element, bool contentOnly, object model)
        {
            Debug.Assert(element != null);

            if (element == Document.Body) {
                // Perform app-level activation (tied to body initialization)

                // Setup top-level services specified declaratively.
                SetupServices();

                // Create the model declaratively associated with the application.
                if (model == null) {
                    string modelTypeName = (string)Document.Body.GetAttribute(ModelTypeAttribute);
                    if (String.IsNullOrEmpty(modelTypeName) == false) {
                        Type modelType = Type.GetType(modelTypeName);
                        Debug.Assert(modelType != null, "Could not resolve model '" + modelTypeName + "'");

                        model = GetObject(modelType);

                        IInitializable initializableModel = model as IInitializable;
                        if (initializableModel != null) {
                            Dictionary<string, object> modelData = OptionsParser.GetOptions(element, "model");
                            initializableModel.BeginInitialization(modelData);
                            initializableModel.EndInitialization();
                        }
                    }
                }

                _model = model;
            }

            // Create expressions and bindings associated with the specified elements and
            // the contained elements. Do this first, as this allows behaviors to look at
            // values set as a result of bindings when they are attached.
            if ((contentOnly == false) && element.HasAttribute(Application.BindingsAttribute)) {
                SetupBindings(element, model);
            }

            ElementCollection boundElements = element.QuerySelectorAll(Application.BindingsSelector);
            for (int i = 0, boundElementCount = boundElements.Length; i < boundElementCount; i++) {
                SetupBindings(boundElements[i], model);
            }

            // Attach behaviors associated declaratively with the specified element and the
            // contained elements.
            if ((contentOnly == false) && element.HasAttribute(Application.BehaviorsAttribute)) {
                AttachBehaviors(element);
            }

            ElementCollection extendedElements = element.QuerySelectorAll(Application.BehaviorsSelector);
            for (int i = 0, extendedElementCount = extendedElements.Length; i < extendedElementCount; i++) {
                AttachBehaviors(extendedElements[i]);
            }
        }