当前位置: 首页>>代码示例>>C#>>正文


C# Element.HasAttribute方法代码示例

本文整理汇总了C#中System.Html.Element.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Element.HasAttribute方法的具体用法?C# Element.HasAttribute怎么用?C# Element.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Html.Element的用法示例。


在下文中一共展示了Element.HasAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupBehaviors

        /// <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]);
                    }
                }
            }
        }
开发者ID:noodlefrenzy,项目名称:scriptsharp,代码行数:25,代码来源:Behavior.cs

示例2: DeactivateFragment

        /// <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]);
                }
            }
        }
开发者ID:nikhilk,项目名称:sharpen,代码行数:24,代码来源:Application.cs

示例3: Initialize

        /// <summary>
        /// Initializes a behavior by attaching it to the specified element.
        /// When overriding this, be sure to call the base functionality before the implementation
        /// in the derived class.
        /// </summary>
        /// <param name="element">The element to attach the behavior to.</param>
        /// <param name="options">Any initialization options that the behavior should consume.</param>
        public virtual void Initialize(Element element, Dictionary<string, object> options)
        {
            Debug.Assert(_element == null, "A behavior should be initialized only once.");
            Debug.Assert(element != null, "Expected a valid element to initialize a behavior.");

            _element = element;

            // Automatically expose the behavior on the DOM element as an expando using
            // the name of the behavior as the key.

            string name = Script.GetField<string>(this.GetType(), Application.BehaviorNameKey);
            Script.SetField(element, name, this);

            // Add a 'behaviors' expando on the element which is a key/value pair
            // list of behavior name -> behavior instance mapping.

            Dictionary<string, Behavior> behaviors = Script.GetField<Dictionary<string, Behavior>>(element, Application.BehaviorsKey);
            if (behaviors == null) {
                behaviors = new Dictionary<string, Behavior>();
                Script.SetField(element, Application.BehaviorsKey, behaviors);
            }

            behaviors[name] = this;

            // Set data-behavior on the element if it is not already set (i.e. if the behavior
            // is being programmatically constructed), so that if DisposeBehaviors is called,
            // then this element is picked up via the CSS query used to find elements that have
            // behaviors.
            if (element.HasAttribute(Application.BehaviorsAttribute) == false) {
                element.SetAttribute(Application.BehaviorsAttribute, String.Empty);
            }
        }
开发者ID:jimmygilles,项目名称:scriptsharp,代码行数:39,代码来源:Behavior.cs

示例4: ActivateFragment

        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]);
            }
        }
开发者ID:nikhilk,项目名称:sharpen,代码行数:54,代码来源:Application.cs


注:本文中的System.Html.Element.HasAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。