GroupDescription.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / System / ComponentModel / GroupDescription.cs / 1305600 / GroupDescription.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) 2003 by Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: Base class for group descriptions. 
//
// See spec at http://avalon/connecteddata/Specs/Grouping.mht 
//
//---------------------------------------------------------------------------

using System.Collections.ObjectModel;   // ObservableCollection 
using System.Collections.Specialized;   // NotifyCollectionChangedEvent*
using System.Globalization;             // CultureInfo 
 
namespace System.ComponentModel
{ 
    /// 
    /// Base class for group descriptions.
    /// A GroupDescription describes how to divide the items in a collection
    /// into groups. 
    /// 
    public abstract class GroupDescription : INotifyPropertyChanged 
    { 
        #region Constructors
 
        //-----------------------------------------------------
        //
        //  Constructors
        // 
        //-----------------------------------------------------
 
        ///  
        /// Initializes a new instance of GroupDescription.
        ///  
        protected GroupDescription()
        {
            _explicitGroupNames = new ObservableCollection();
            _explicitGroupNames.CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupNamesChanged); 
        }
 
        #endregion Constructors 

        #region INotifyPropertyChanged 

        /// 
        ///     This event is raised when a property of the group description has changed.
        ///  
        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        { 
            add 
            {
                PropertyChanged += value; 
            }
            remove
            {
                PropertyChanged -= value; 
            }
        } 
 
        /// 
        /// PropertyChanged event (per ). 
        /// 
        protected virtual event PropertyChangedEventHandler PropertyChanged;

        ///  
        /// A subclass can call this method to raise the PropertyChanged event.
        ///  
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) 
        {
            if (PropertyChanged != null) 
            {
                PropertyChanged(this, e);
            }
        } 

        #endregion INotifyPropertyChanged 
 
        #region Public Properties
 
        //------------------------------------------------------
        //
        //  Public Properties
        // 
        //-----------------------------------------------------
 
        ///  
        /// This list of names is used to initialize a group with a set of
        /// subgroups with the given names.  (Additional subgroups may be 
        /// added later, if there are items that don't match any of the names.)
        /// 
        public ObservableCollection GroupNames
        { 
            get { return _explicitGroupNames; }
        } 
 
        /// 
        /// This method is used by TypeDescriptor to determine if this property should 
        /// be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeGroupNames() 
        {
            return (_explicitGroupNames.Count > 0); 
        } 

        #endregion Public Properties 

        #region Public Methods

        //------------------------------------------------------ 
        //
        //  Public Methods 
        // 
        //------------------------------------------------------
 
        /// 
        /// Return the group name(s) for the given item
        /// 
        public abstract object GroupNameFromItem(object item, int level, CultureInfo culture); 

        ///  
        /// Return true if the names match (i.e the item should belong to the group). 
        /// 
        public virtual bool NamesMatch(object groupName, object itemName) 
        {
            return Object.Equals(groupName, itemName);
        }
 
        #endregion Public Methods
 
        #region Private Methods 

        //----------------------------------------------------- 
        //
        //  Private Methods
        //
        //------------------------------------------------------ 

        void OnGroupNamesChanged(object sender, NotifyCollectionChangedEventArgs e) 
        { 
            OnPropertyChanged(new PropertyChangedEventArgs("GroupNames"));
        } 

        #endregion Private Methods

        #region Private fields 

        //----------------------------------------------------- 
        // 
        //  Private fields
        // 
        //-----------------------------------------------------

        ObservableCollection _explicitGroupNames;
 
        #endregion Private fields
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) 2003 by Microsoft Corporation.  All rights reserved.
//  
//
// 
// Description: Base class for group descriptions. 
//
// See spec at http://avalon/connecteddata/Specs/Grouping.mht 
//
//---------------------------------------------------------------------------

using System.Collections.ObjectModel;   // ObservableCollection 
using System.Collections.Specialized;   // NotifyCollectionChangedEvent*
using System.Globalization;             // CultureInfo 
 
namespace System.ComponentModel
{ 
    /// 
    /// Base class for group descriptions.
    /// A GroupDescription describes how to divide the items in a collection
    /// into groups. 
    /// 
    public abstract class GroupDescription : INotifyPropertyChanged 
    { 
        #region Constructors
 
        //-----------------------------------------------------
        //
        //  Constructors
        // 
        //-----------------------------------------------------
 
        ///  
        /// Initializes a new instance of GroupDescription.
        ///  
        protected GroupDescription()
        {
            _explicitGroupNames = new ObservableCollection();
            _explicitGroupNames.CollectionChanged += new NotifyCollectionChangedEventHandler(OnGroupNamesChanged); 
        }
 
        #endregion Constructors 

        #region INotifyPropertyChanged 

        /// 
        ///     This event is raised when a property of the group description has changed.
        ///  
        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        { 
            add 
            {
                PropertyChanged += value; 
            }
            remove
            {
                PropertyChanged -= value; 
            }
        } 
 
        /// 
        /// PropertyChanged event (per ). 
        /// 
        protected virtual event PropertyChangedEventHandler PropertyChanged;

        ///  
        /// A subclass can call this method to raise the PropertyChanged event.
        ///  
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) 
        {
            if (PropertyChanged != null) 
            {
                PropertyChanged(this, e);
            }
        } 

        #endregion INotifyPropertyChanged 
 
        #region Public Properties
 
        //------------------------------------------------------
        //
        //  Public Properties
        // 
        //-----------------------------------------------------
 
        ///  
        /// This list of names is used to initialize a group with a set of
        /// subgroups with the given names.  (Additional subgroups may be 
        /// added later, if there are items that don't match any of the names.)
        /// 
        public ObservableCollection GroupNames
        { 
            get { return _explicitGroupNames; }
        } 
 
        /// 
        /// This method is used by TypeDescriptor to determine if this property should 
        /// be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeGroupNames() 
        {
            return (_explicitGroupNames.Count > 0); 
        } 

        #endregion Public Properties 

        #region Public Methods

        //------------------------------------------------------ 
        //
        //  Public Methods 
        // 
        //------------------------------------------------------
 
        /// 
        /// Return the group name(s) for the given item
        /// 
        public abstract object GroupNameFromItem(object item, int level, CultureInfo culture); 

        ///  
        /// Return true if the names match (i.e the item should belong to the group). 
        /// 
        public virtual bool NamesMatch(object groupName, object itemName) 
        {
            return Object.Equals(groupName, itemName);
        }
 
        #endregion Public Methods
 
        #region Private Methods 

        //----------------------------------------------------- 
        //
        //  Private Methods
        //
        //------------------------------------------------------ 

        void OnGroupNamesChanged(object sender, NotifyCollectionChangedEventArgs e) 
        { 
            OnPropertyChanged(new PropertyChangedEventArgs("GroupNames"));
        } 

        #endregion Private Methods

        #region Private fields 

        //----------------------------------------------------- 
        // 
        //  Private fields
        // 
        //-----------------------------------------------------

        ObservableCollection _explicitGroupNames;
 
        #endregion Private fields
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK