Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Data / PropertyGroupDescription.cs / 1305600 / PropertyGroupDescription.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//
//
// Description: Description of grouping based on a property value.
//
// See spec at http://avalon/connecteddata/Specs/Grouping.mht
//
//---------------------------------------------------------------------------
using System; // StringComparison
using System.ComponentModel; // [DefaultValue]
using System.Globalization; // CultureInfo
using System.Reflection; // PropertyInfo
using System.Windows; // SR
using System.Xml; // XmlNode
using MS.Internal; // XmlHelper
namespace System.Windows.Data
{
///
/// Description of grouping based on a property value.
///
public class PropertyGroupDescription : GroupDescription
{
#region Constructors
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance of PropertyGroupDescription.
///
public PropertyGroupDescription()
{
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
public PropertyGroupDescription(string propertyName)
{
UpdatePropertyName(propertyName);
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
public PropertyGroupDescription(string propertyName,
IValueConverter converter)
{
UpdatePropertyName(propertyName);
_converter = converter;
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
///
/// This governs the comparison between an item's value (as determined
/// by PropertyName and Converter) and a group's name.
/// It is ignored unless both comparands are strings.
/// The default value is StringComparison.Ordinal.
///
public PropertyGroupDescription(string propertyName,
IValueConverter converter,
StringComparison stringComparison)
{
UpdatePropertyName(propertyName);
_converter = converter;
_stringComparison = stringComparison;
}
#endregion Constructors
#region Public Properties
//------------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
[DefaultValue(null)]
public string PropertyName
{
get { return _propertyName; }
set
{
UpdatePropertyName(value);
OnPropertyChanged("PropertyName");
}
}
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
[DefaultValue(null)]
public IValueConverter Converter
{
get { return _converter; }
set { _converter = value; OnPropertyChanged("Converter"); }
}
///
/// This governs the comparison between an item's value (as determined
/// by PropertyName and Converter) and a group's name.
/// It is ignored unless both comparands are strings.
/// The default value is StringComparison.Ordinal.
///
[DefaultValue(StringComparison.Ordinal)]
public StringComparison StringComparison
{
get { return _stringComparison; }
set { _stringComparison = value; OnPropertyChanged("StringComparison"); }
}
#endregion Public Properties
#region Public Methods
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
///
/// Return the group name(s) for the given item
///
public override object GroupNameFromItem(object item, int level, CultureInfo culture)
{
object value;
object xmlValue;
// get the property value
if (String.IsNullOrEmpty(PropertyName))
{
value = item;
}
else if (AssemblyHelper.TryGetValueFromXmlNode(item, PropertyName, out xmlValue))
{
value = xmlValue;
}
else if (item != null)
{
using (_propertyPath.SetContext(item))
{
value = _propertyPath.GetValue();
}
}
else
{
value = null;
}
// apply the converter to the value
if (Converter != null)
{
value = Converter.Convert(value, typeof(object), level, culture);
}
return value;
}
///
/// Return true if the names match (i.e the item should belong to the group).
///
public override bool NamesMatch(object groupName, object itemName)
{
string s1 = groupName as string;
string s2 = itemName as string;
if (s1 != null && s2 != null)
{
return String.Equals(s1, s2, StringComparison);
}
else
{
return Object.Equals(groupName, itemName);
}
}
#endregion Public Methods
#region Private Methods
private void UpdatePropertyName(string propertyName)
{
_propertyName = propertyName;
_propertyPath = !String.IsNullOrEmpty(propertyName) ? new PropertyPath(propertyName) : null;
}
private void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
#endregion Private Methods
#region Private Fields
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
string _propertyName;
PropertyPath _propertyPath;
IValueConverter _converter;
StringComparison _stringComparison = StringComparison.Ordinal;
#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: Description of grouping based on a property value.
//
// See spec at http://avalon/connecteddata/Specs/Grouping.mht
//
//---------------------------------------------------------------------------
using System; // StringComparison
using System.ComponentModel; // [DefaultValue]
using System.Globalization; // CultureInfo
using System.Reflection; // PropertyInfo
using System.Windows; // SR
using System.Xml; // XmlNode
using MS.Internal; // XmlHelper
namespace System.Windows.Data
{
///
/// Description of grouping based on a property value.
///
public class PropertyGroupDescription : GroupDescription
{
#region Constructors
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance of PropertyGroupDescription.
///
public PropertyGroupDescription()
{
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
public PropertyGroupDescription(string propertyName)
{
UpdatePropertyName(propertyName);
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
public PropertyGroupDescription(string propertyName,
IValueConverter converter)
{
UpdatePropertyName(propertyName);
_converter = converter;
}
///
/// Initializes a new instance of PropertyGroupDescription.
///
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
///
/// This governs the comparison between an item's value (as determined
/// by PropertyName and Converter) and a group's name.
/// It is ignored unless both comparands are strings.
/// The default value is StringComparison.Ordinal.
///
public PropertyGroupDescription(string propertyName,
IValueConverter converter,
StringComparison stringComparison)
{
UpdatePropertyName(propertyName);
_converter = converter;
_stringComparison = stringComparison;
}
#endregion Constructors
#region Public Properties
//------------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
///
/// The name of the property whose value is used to determine which group(s)
/// an item belongs to.
/// If PropertyName is null, the item itself is used.
///
[DefaultValue(null)]
public string PropertyName
{
get { return _propertyName; }
set
{
UpdatePropertyName(value);
OnPropertyChanged("PropertyName");
}
}
///
/// This converter is applied to the property value (or the item) to
/// produce the final value used to determine which group(s) an item
/// belongs to.
/// If the delegate returns an ICollection, the item is added to
/// multiple groups - one for each member of the collection.
///
[DefaultValue(null)]
public IValueConverter Converter
{
get { return _converter; }
set { _converter = value; OnPropertyChanged("Converter"); }
}
///
/// This governs the comparison between an item's value (as determined
/// by PropertyName and Converter) and a group's name.
/// It is ignored unless both comparands are strings.
/// The default value is StringComparison.Ordinal.
///
[DefaultValue(StringComparison.Ordinal)]
public StringComparison StringComparison
{
get { return _stringComparison; }
set { _stringComparison = value; OnPropertyChanged("StringComparison"); }
}
#endregion Public Properties
#region Public Methods
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
///
/// Return the group name(s) for the given item
///
public override object GroupNameFromItem(object item, int level, CultureInfo culture)
{
object value;
object xmlValue;
// get the property value
if (String.IsNullOrEmpty(PropertyName))
{
value = item;
}
else if (AssemblyHelper.TryGetValueFromXmlNode(item, PropertyName, out xmlValue))
{
value = xmlValue;
}
else if (item != null)
{
using (_propertyPath.SetContext(item))
{
value = _propertyPath.GetValue();
}
}
else
{
value = null;
}
// apply the converter to the value
if (Converter != null)
{
value = Converter.Convert(value, typeof(object), level, culture);
}
return value;
}
///
/// Return true if the names match (i.e the item should belong to the group).
///
public override bool NamesMatch(object groupName, object itemName)
{
string s1 = groupName as string;
string s2 = itemName as string;
if (s1 != null && s2 != null)
{
return String.Equals(s1, s2, StringComparison);
}
else
{
return Object.Equals(groupName, itemName);
}
}
#endregion Public Methods
#region Private Methods
private void UpdatePropertyName(string propertyName)
{
_propertyName = propertyName;
_propertyPath = !String.IsNullOrEmpty(propertyName) ? new PropertyPath(propertyName) : null;
}
private void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
#endregion Private Methods
#region Private Fields
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
string _propertyName;
PropertyPath _propertyPath;
IValueConverter _converter;
StringComparison _stringComparison = StringComparison.Ordinal;
#endregion Private Fields
}
}
// 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
- WindowsContainer.cs
- SqlLiftIndependentRowExpressions.cs
- XPathAncestorQuery.cs
- XmlLanguage.cs
- RegexCode.cs
- QueryConverter.cs
- HtmlHistory.cs
- SchemaCollectionCompiler.cs
- PropertyInformation.cs
- TracingConnectionInitiator.cs
- TiffBitmapEncoder.cs
- DataKey.cs
- GridViewSelectEventArgs.cs
- XPathSelectionIterator.cs
- HideDisabledControlAdapter.cs
- WindowsTitleBar.cs
- ToolTip.cs
- RowSpanVector.cs
- PermissionSetTriple.cs
- XPathDocument.cs
- ClientSettingsSection.cs
- Hashtable.cs
- ChannelRequirements.cs
- GifBitmapEncoder.cs
- SoapMessage.cs
- TimeoutException.cs
- LookupBindingPropertiesAttribute.cs
- Rotation3DAnimation.cs
- ViewLoader.cs
- XamlStream.cs
- Cursor.cs
- HashAlgorithm.cs
- VirtualizedCellInfoCollection.cs
- AsyncContentLoadedEventArgs.cs
- OdbcConnection.cs
- TextSchema.cs
- ChannelServices.cs
- DeclarativeExpressionConditionDeclaration.cs
- TransformPatternIdentifiers.cs
- MeshGeometry3D.cs
- ThrowHelper.cs
- CompoundFileReference.cs
- GuidConverter.cs
- LineMetrics.cs
- TableAutomationPeer.cs
- OleAutBinder.cs
- WaitHandle.cs
- SqlDataSource.cs
- CodeThrowExceptionStatement.cs
- TableCellCollection.cs
- GetImportedCardRequest.cs
- cookie.cs
- XmlSchemaComplexContentExtension.cs
- Pair.cs
- ToolStripRenderEventArgs.cs
- ToolZone.cs
- CommandHelper.cs
- ApplicationServiceHelper.cs
- Executor.cs
- MetaTable.cs
- SafeArrayTypeMismatchException.cs
- SqlStream.cs
- SqlVersion.cs
- AddingNewEventArgs.cs
- ProcessModule.cs
- UrlPath.cs
- CurrentChangingEventArgs.cs
- XPathPatternBuilder.cs
- VisualBasicSettingsConverter.cs
- MiniConstructorInfo.cs
- CollectionAdapters.cs
- Line.cs
- ProtocolsConfigurationHandler.cs
- FlowchartDesigner.Helpers.cs
- ImplicitInputBrush.cs
- CompositeControl.cs
- CompoundFileIOPermission.cs
- BuildResult.cs
- InvalidCommandTreeException.cs
- MarginCollapsingState.cs
- ByteArrayHelperWithString.cs
- NetworkCredential.cs
- httpstaticobjectscollection.cs
- SQLSingle.cs
- VirtualizingPanel.cs
- ObjectSet.cs
- FormViewPageEventArgs.cs
- RecognizerInfo.cs
- FixedPageStructure.cs
- SqlCommandBuilder.cs
- FixedDSBuilder.cs
- CodeTypeOfExpression.cs
- ParseChildrenAsPropertiesAttribute.cs
- AssemblyBuilder.cs
- SqlWebEventProvider.cs
- formatter.cs
- DisplayNameAttribute.cs
- TypeContext.cs
- Quad.cs
- HttpContext.cs