⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accordion.cs

📁 AJAX 应用 实现页面的无刷新
💻 CS
📖 第 1 页 / 共 3 页
字号:
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AjaxControlToolkit
{
    /// <summary>
    /// The Accordion control represents a series of panes that can be viewed
    /// one at a time.  The control is used to create "strongly typed" access
    /// to the AccordionBehavior.  Its major purpose is to structure the content
    /// in a way that the AccordionBehavior can understand it.  We need a series
    /// of HTML container elements, such as divs, that looks like the following:
    ///   <div id="Accordion">
    ///     <span id="AccordionPane1">
    ///       <div id="AccordionPane1Header"></div>
    ///       <div id="AccordionPane1Content"></div>
    ///     </span>
    ///     <span id="AccordionPane2">
    ///       <div id="AccordionPane2Header"></div>
    ///       <div id="AccordionPane2Content"></div>
    ///     </span>
    ///     .
    ///     .
    ///     .
    ///   </div>
    /// </summary>
    [ParseChildren(true)]
    [PersistChildren(true)]
    [Designer("AjaxControlToolkit.AccordionDesigner, AjaxControlToolkit")]
    [ToolboxData("<{0}:Accordion runat=server></{0}:Accordion>")]
    [System.Drawing.ToolboxBitmap(typeof(Accordion), "Accordion.Accordion.ico")]
    public class Accordion : WebControl
    {
        /// <summary>
        /// ViewState key for tracking the number of panes in the Accordion
        /// </summary>
        internal const string ItemCountViewStateKey = "_!ItemCount";

        /// <summary>
        /// Event to raise when an item (i.e. Pane's Header or Content) is
        /// created during data binding
        /// </summary>
        public event EventHandler<AccordionItemEventArgs> ItemCreated;

        /// <summary>
        /// Event to raise when an item (i.e. Pane's Header or Content) is
        /// data bound
        /// </summary>
        public event EventHandler<AccordionItemEventArgs> ItemDataBound;

        /// <summary>
        /// Event to raise when a command is fired
        /// </summary>
        public event CommandEventHandler ItemCommand;

        /// <summary>
        /// AccordionExtender to attach
        /// </summary>
        private AccordionExtender _extender;

        /// <summary>
        /// The Accordion's child panes
        /// </summary>
        private AccordionPaneCollection _panes;

#region DataBinding Fields

        /// <summary>
        /// DataSource to bind the Accordion to
        /// </summary>
        private object _dataSource;

        /// <summary>
        /// DataBinding template for the header
        /// </summary>
        private ITemplate _headerTemplate;

        /// <summary>
        /// DataBinding template for the content
        /// </summary>
        private ITemplate _contentTemplate;

        /// <summary>
        /// Whether or not the control has been initialized
        /// </summary>
        private bool _initialized;

        /// <summary>
        /// Whether the page's PreLoad event has already fired
        /// </summary>
        private bool _pagePreLoadFired;

        /// <summary>
        /// Whether or not the Accordion needs to be databound but hasn't been yet
        /// </summary>
        private bool _requiresDataBinding;

        /// <summary>
        /// Flag to determine if we should throw an exception when a data property
        /// (i.e. DataSource, DataSourceID, DataMember) is changed
        /// </summary>
        private bool _throwOnDataPropertyChange;

        /// <summary>
        /// View of the the data provided by the data property
        /// </summary>
        private DataSourceView _currentView;

        /// <summary>
        /// Whether the current DataSourceView was loaded from a DataSourceID
        /// </summary>
        private bool _currentViewIsFromDataSourceID;

        /// <summary>
        /// Whether the current DataSourceView contains valid data
        /// </summary>
        private bool _currentViewValid;

        /// <summary>
        /// Arguments used to sort, filter, etc., the data when creating
        /// the DataSourceView (although we will use the default whenever possible)
        /// </summary>
        private DataSourceSelectArguments _arguments;

        /// <summary>
        /// Enumerable list of data items obtained from the DataSource
        /// </summary>
        IEnumerable _selectResult;

        /// <summary>
        /// Thread synchronization event used for obtaining data from the DataSource
        /// </summary>
        EventWaitHandle _selectWait;

#endregion

        /// <summary>
        /// Default constructor that tells ASP.NET to render it as a DIV
        /// </summary>
        public Accordion()
            : base(HtmlTextWriterTag.Div)
        {
        }

        /// <summary>
        /// Reference to the AccordionExtender wrapped by the Accordion control
        /// </summary>
        /// <remarks>
        /// This will be referenced in CreateChildControls so that the extender
        /// will always be created by any calls to EnsureChildControls.
        /// </remarks>
        private AccordionExtender AccordionExtender
        {
            get
            {
                if (_extender == null)
                {
                    // Create the extender
                    _extender = new AccordionExtender();
                    _extender.ID = ID + "_AccordionExtender";
                    _extender.TargetControlID = ID;
                    Controls.AddAt(0, _extender);
                }
                return _extender;
            }
        }

        /// <summary>
        /// Length of the transition animation in milliseconds
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Length of the transition animation in milliseconds")]
        [DefaultValue(500)]
        public int TransitionDuration
        {
            get { return AccordionExtender.TransitionDuration; }
            set { AccordionExtender.TransitionDuration = value; }
        }

        /// <summary>
        /// The number of frames per second used in the transition animation effects.
        /// This is used to tune performance when using FadeTransition, a large number
        /// of Accordion Panes, etc.
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Number of frames per second used in the transition animation")]
        [DefaultValue(15)]
        public int FramesPerSecond
        {
            get { return AccordionExtender.FramesPerSecond; }
            set { AccordionExtender.FramesPerSecond = value; }
        }

        /// <summary>
        /// Whether or not to use a fade effect when transitioning between selected
        /// Accordion Panes
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Whether or not to use a fade effect in the transition animations")]
        [DefaultValue(false)]
        public bool FadeTransitions
        {
            get { return AccordionExtender.FadeTransitions; }
            set { AccordionExtender.FadeTransitions = value; }
        }

        /// <summary>
        /// Default Header CSS Class
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("Default CSS class for Accordion Pane Headers")]
        public string HeaderCssClass
        {
            get { return AccordionExtender.HeaderCssClass; }
            set { AccordionExtender.HeaderCssClass = value; }
        }

        /// <summary>
        /// Default selected Header CSS Class
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("Default CSS class for the selected Accordion Pane Headers")]
        public string HeaderSelectedCssClass
        {
            get { return AccordionExtender.HeaderSelectedCssClass; }
            set { AccordionExtender.HeaderSelectedCssClass = value; }
        }

        /// <summary>
        /// Default Content CSS Class
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("Default CSS class for Accordion Pane Content")]
        public string ContentCssClass
        {
            get { return AccordionExtender.ContentCssClass; }
            set { AccordionExtender.ContentCssClass = value; }
        }

        /// <summary>
        /// Determine how growth of the Accordion will be controlled.  If it is set to
        /// None, then the Accordion can grow as large or as small as necessary.  If it is
        /// set to Limit, then the Accordion will always be less than or equal to its
        /// Height.  If it is set to Fill then it will always be equal to its height.
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Determine how the growth of the Accordion will be controlled")]
        [DefaultValue(AutoSize.None)]
        public AutoSize AutoSize
        {
            get { return AccordionExtender.AutoSize; }
            set { AccordionExtender.AutoSize = value; }
        }

        /// <summary>
        /// Index of the AccordionPane to be displayed
        /// (this property must be set before OnPreRender)
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Index of the AccordionPane to be displayed")]
        [DefaultValue(0)]
        public int SelectedIndex
        {
            get { return AccordionExtender.SelectedIndex; }
            set { AccordionExtender.SelectedIndex = value; }
        }

        /// <summary>
        /// Whether or not clicking the header will close the currently opened pane (leaving
        /// all the Accordion's panes closed)
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Whether or not clicking the header will close the currently opened pane (leaving all the Accordion's panes closed)")]
        [DefaultValue(true)]
        public bool RequireOpenedPane
        {
            get { return AccordionExtender.RequireOpenedPane; }
            set { AccordionExtender.RequireOpenedPane = value; }
        }

        /// <summary>
        /// Whether or not we suppress the client-side click handlers of any elements (including server
        /// controls like Button or HTML elements like anchor) in the header sections of the Accordion.
        /// </summary>
        [Browsable(true)]
        [Category("Behavior")]
        [Description("Whether or not we suppress the client-side click handlers of any elements in the header sections")]
        [DefaultValue(false)]
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Postbacks", Justification="ASP.NET term")]
        public bool SuppressHeaderPostbacks
        {
            get { return AccordionExtender.SuppressHeaderPostbacks; }
            set { AccordionExtender.SuppressHeaderPostbacks = value; }
        }

        /// <summary>
        /// Collection of child panes in the Accordion
        /// </summary>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public AccordionPaneCollection Panes
        {
            get
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -