Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Annotations / AnnotationResourceCollection.cs / 1305600 / AnnotationResourceCollection.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//
// Description: Subclass of AnnotationObservableCollection which has slightly different
// eventing behavior for ClearItems and SetItem methods. This class
// is used specifically for AnnotationResources.
//
// History:
// 03/10/2005 : rruiz - created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Annotations;
using System.Windows.Data;
namespace MS.Internal.Annotations
{
///
/// Subclass of AnnotationObservableCollection which has slightly different
/// eventing behavior for ClearItems and SetItem methods. This class
/// is used specifically for AnnotationResources.
///
internal sealed class AnnotationResourceCollection : AnnotationObservableCollection
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Initializes a new instance of AnnotationResourceCollection that is empty and has default initial capacity.
///
public AnnotationResourceCollection() : base()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Public Events
//
//-----------------------------------------------------
#region Public Events
///
/// Event fired when an item in the collection changes (fires a PropertyChanged event).
///
public event PropertyChangedEventHandler ItemChanged;
#endregion Public Events
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// Override this method and provide a different set of events
/// when items are cleared from the collection. Specifically,
/// fire a Remove event for each item in the collection.
///
protected override void ProtectedClearItems()
{
// We want to fire for each item in the list
List list = new List(this);
Items.Clear(); // directly clear Collection inner Items collection
OnPropertyChanged(CountString);
OnPropertyChanged(IndexerName);
OnCollectionCleared(list);
}
///
/// Override this method and provide a different set of events
/// when an item is set on a given index in this collection.
/// Specifically, fire a both a Remove and Add event (as the
/// grand-parent class ObservableCollection does).
///
/// index of item to set
/// item to set at that index
protected override void ProtectedSetItem(int index, AnnotationResource item)
{
// Use the standard built in events (one for item removed and one for item added)
ObservableCollectionSetItem(index, item); // Calls raw ObservableCollection method
}
#endregion Protected Methods
//-----------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
// fire an event for each item removed from the collection
void OnCollectionCleared(IEnumerable list)
{
foreach(object item in list)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, 0));
}
}
private void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
// raise CollectionChanged event to any listeners
protected override void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (ItemChanged != null)
{
ItemChanged(sender, e);
}
}
#endregion Private Methods
}
}
// 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: Subclass of AnnotationObservableCollection which has slightly different
// eventing behavior for ClearItems and SetItem methods. This class
// is used specifically for AnnotationResources.
//
// History:
// 03/10/2005 : rruiz - created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Annotations;
using System.Windows.Data;
namespace MS.Internal.Annotations
{
///
/// Subclass of AnnotationObservableCollection which has slightly different
/// eventing behavior for ClearItems and SetItem methods. This class
/// is used specifically for AnnotationResources.
///
internal sealed class AnnotationResourceCollection : AnnotationObservableCollection
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Initializes a new instance of AnnotationResourceCollection that is empty and has default initial capacity.
///
public AnnotationResourceCollection() : base()
{
}
#endregion Constructors
//------------------------------------------------------
//
// Public Events
//
//-----------------------------------------------------
#region Public Events
///
/// Event fired when an item in the collection changes (fires a PropertyChanged event).
///
public event PropertyChangedEventHandler ItemChanged;
#endregion Public Events
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// Override this method and provide a different set of events
/// when items are cleared from the collection. Specifically,
/// fire a Remove event for each item in the collection.
///
protected override void ProtectedClearItems()
{
// We want to fire for each item in the list
List list = new List(this);
Items.Clear(); // directly clear Collection inner Items collection
OnPropertyChanged(CountString);
OnPropertyChanged(IndexerName);
OnCollectionCleared(list);
}
///
/// Override this method and provide a different set of events
/// when an item is set on a given index in this collection.
/// Specifically, fire a both a Remove and Add event (as the
/// grand-parent class ObservableCollection does).
///
/// index of item to set
/// item to set at that index
protected override void ProtectedSetItem(int index, AnnotationResource item)
{
// Use the standard built in events (one for item removed and one for item added)
ObservableCollectionSetItem(index, item); // Calls raw ObservableCollection method
}
#endregion Protected Methods
//-----------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
// fire an event for each item removed from the collection
void OnCollectionCleared(IEnumerable list)
{
foreach(object item in list)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, 0));
}
}
private void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
// raise CollectionChanged event to any listeners
protected override void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (ItemChanged != null)
{
ItemChanged(sender, e);
}
}
#endregion Private Methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageParser.cs
- ToolStripDropDown.cs
- XmlSortKey.cs
- UniqueIdentifierService.cs
- DbConnectionFactory.cs
- OrderedEnumerableRowCollection.cs
- EncryptedXml.cs
- SqlNodeAnnotations.cs
- ListItemsPage.cs
- ExpandCollapsePattern.cs
- ChainedAsyncResult.cs
- ReflectTypeDescriptionProvider.cs
- StorageEndPropertyMapping.cs
- Peer.cs
- GridViewRow.cs
- codemethodreferenceexpression.cs
- BaseCollection.cs
- AuthenticationManager.cs
- OdbcConnectionPoolProviderInfo.cs
- MembershipSection.cs
- EventMap.cs
- ConnectionManagementSection.cs
- GridViewRowCollection.cs
- SizeLimitedCache.cs
- ArrowControl.xaml.cs
- RuleSetDialog.cs
- LoginName.cs
- TextTreeDeleteContentUndoUnit.cs
- Version.cs
- CodeMemberEvent.cs
- propertyentry.cs
- BuildProvidersCompiler.cs
- XmlSchemaInfo.cs
- DynamicValueConverter.cs
- compensatingcollection.cs
- SHA512Managed.cs
- GradientSpreadMethodValidation.cs
- TemplateControlBuildProvider.cs
- AppModelKnownContentFactory.cs
- Baml6Assembly.cs
- TextServicesLoader.cs
- KnownIds.cs
- DbReferenceCollection.cs
- _AutoWebProxyScriptEngine.cs
- ArrayList.cs
- FrameworkTemplate.cs
- DBBindings.cs
- ImmutableClientRuntime.cs
- Comparer.cs
- WindowVisualStateTracker.cs
- ButtonBase.cs
- SemanticBasicElement.cs
- AudioLevelUpdatedEventArgs.cs
- ExpressionBuilderContext.cs
- CLSCompliantAttribute.cs
- BitSet.cs
- smtpconnection.cs
- BulletedList.cs
- FutureFactory.cs
- TreeView.cs
- SettingsAttributeDictionary.cs
- Helpers.cs
- _LocalDataStoreMgr.cs
- WorkflowFileItem.cs
- ApplicationFileCodeDomTreeGenerator.cs
- PropertyMapper.cs
- ScrollContentPresenter.cs
- ServiceXNameTypeConverter.cs
- WsatTransactionHeader.cs
- ProgressiveCrcCalculatingStream.cs
- ResolveRequestResponseAsyncResult.cs
- SEHException.cs
- SpecialNameAttribute.cs
- WCFServiceClientProxyGenerator.cs
- VersionedStream.cs
- IdentitySection.cs
- StrongNameKeyPair.cs
- CreateUserErrorEventArgs.cs
- EventEntry.cs
- ValidationSummary.cs
- LinqDataSourceSelectEventArgs.cs
- XmlSchemaComplexType.cs
- ConfigurationPropertyCollection.cs
- AnnotationResourceChangedEventArgs.cs
- DispatcherTimer.cs
- webbrowsersite.cs
- JpegBitmapEncoder.cs
- VerticalAlignConverter.cs
- BidirectionalDictionary.cs
- GlyphShapingProperties.cs
- StylusButtonCollection.cs
- DocumentScope.cs
- ItemsPanelTemplate.cs
- HttpHeaderCollection.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- XmlChildEnumerator.cs
- ConsoleTraceListener.cs
- WindowsGrip.cs
- XmlNamespaceManager.cs
- DocumentXmlWriter.cs