Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / GridLength.cs / 1305600 / GridLength.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Grid length implementation
//
// See spec at http://avalon/layout/Specs/Star%20LengthUnit.mht
//
// History:
// 09/24/2003 : olego - Created (in griddy prototype branch);
// 10/27/2003 : olego - Ported from griddy prototype branch;
//
//---------------------------------------------------------------------------
using MS.Internal;
using System.ComponentModel;
using System.Globalization;
namespace System.Windows
{
///
/// GridUnitType enum is used to indicate what kind of value the
/// GridLength is holding.
///
// Note: Keep the GridUnitType enum in [....] with the string representation
// of units (GridLengthConverter._unitString).
public enum GridUnitType
{
///
/// The value indicates that content should be calculated without constraints.
///
Auto = 0,
///
/// The value is expressed as a pixel.
///
Pixel,
///
/// The value is expressed as a weighted proportion of available space.
///
Star,
}
///
/// GridLength is the type used for various length-like properties in the system,
/// that explicitely support Star unit type. For example, "Width", "Height"
/// properties of ColumnDefinition and RowDefinition used by Grid.
///
[TypeConverter(typeof(GridLengthConverter))]
public struct GridLength : IEquatable
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor, initializes the GridLength as absolute value in pixels.
///
/// Specifies the number of 'device-independent pixels'
/// (96 pixels-per-inch).
///
/// If pixels parameter is double.NaN
/// or pixels parameter is double.NegativeInfinity
/// or pixels parameter is double.PositiveInfinity .
///
public GridLength(double pixels)
: this(pixels, GridUnitType.Pixel)
{
}
///
/// Constructor, initializes the GridLength and specifies what kind of value
/// it will hold.
///
/// Value to be stored by this GridLength
/// instance.
/// Type of the value to be stored by this GridLength
/// instance.
///
/// If the type parameter is GridUnitType.Auto ,
/// then passed in value is ignored and replaced with 0 .
///
///
/// If value parameter is double.NaN
/// or value parameter is double.NegativeInfinity
/// or value parameter is double.PositiveInfinity .
///
public GridLength(double value, GridUnitType type)
{
if (DoubleUtil.IsNaN(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value"));
}
if (double.IsInfinity(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoInfinity, "value"));
}
if ( type != GridUnitType.Auto
&& type != GridUnitType.Pixel
&& type != GridUnitType.Star )
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterUnknownGridUnitType, "type"));
}
_unitValue = (type == GridUnitType.Auto) ? 0.0 : value;
_unitType = type;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Overloaded operator, compares 2 GridLength's.
///
/// first GridLength to compare.
/// second GridLength to compare.
/// true if specified GridLengths have same value
/// and unit type.
public static bool operator == (GridLength gl1, GridLength gl2)
{
return ( gl1.GridUnitType == gl2.GridUnitType
&& gl1.Value == gl2.Value );
}
///
/// Overloaded operator, compares 2 GridLength's.
///
/// first GridLength to compare.
/// second GridLength to compare.
/// true if specified GridLengths have either different value or
/// unit type.
public static bool operator != (GridLength gl1, GridLength gl2)
{
return ( gl1.GridUnitType != gl2.GridUnitType
|| gl1.Value != gl2.Value );
}
///
/// Compares this instance of GridLength with another object.
///
/// Reference to an object for comparison.
/// true if this GridLength instance has the same value
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
if(oCompare is GridLength)
{
GridLength l = (GridLength)oCompare;
return (this == l);
}
else
return false;
}
///
/// Compares this instance of GridLength with another instance.
///
/// Grid length instance to compare.
/// true if this GridLength instance has the same value
/// and unit type as gridLength.
public bool Equals(GridLength gridLength)
{
return (this == gridLength);
}
///
///
///
///
public override int GetHashCode()
{
return ((int)_unitValue + (int)_unitType);
}
///
/// Returns true if this GridLength instance holds
/// an absolute (pixel) value.
///
public bool IsAbsolute { get { return (_unitType == GridUnitType.Pixel); } }
///
/// Returns true if this GridLength instance is
/// automatic (not specified).
///
public bool IsAuto { get { return (_unitType == GridUnitType.Auto); } }
///
/// Returns true if this GridLength instance holds weighted propertion
/// of available space.
///
public bool IsStar { get { return (_unitType == GridUnitType.Star); } }
///
/// Returns value part of this GridLength instance.
///
public double Value { get { return ((_unitType == GridUnitType.Auto) ? 1.0 : _unitValue); } }
///
/// Returns unit type of this GridLength instance.
///
public GridUnitType GridUnitType { get { return (_unitType); } }
///
/// Returns the string representation of this object.
///
public override string ToString()
{
return GridLengthConverter.ToString(this, CultureInfo.InvariantCulture);
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
#region Public Properties
///
/// Returns initialized Auto GridLength value.
///
public static GridLength Auto
{
get { return (s_auto); }
}
#endregion Public Properties
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private double _unitValue; // unit value storage
private GridUnitType _unitType; // unit type storage
// static instance of Auto GridLength
private static readonly GridLength s_auto = new GridLength(1.0, GridUnitType.Auto);
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Grid length implementation
//
// See spec at http://avalon/layout/Specs/Star%20LengthUnit.mht
//
// History:
// 09/24/2003 : olego - Created (in griddy prototype branch);
// 10/27/2003 : olego - Ported from griddy prototype branch;
//
//---------------------------------------------------------------------------
using MS.Internal;
using System.ComponentModel;
using System.Globalization;
namespace System.Windows
{
///
/// GridUnitType enum is used to indicate what kind of value the
/// GridLength is holding.
///
// Note: Keep the GridUnitType enum in [....] with the string representation
// of units (GridLengthConverter._unitString).
public enum GridUnitType
{
///
/// The value indicates that content should be calculated without constraints.
///
Auto = 0,
///
/// The value is expressed as a pixel.
///
Pixel,
///
/// The value is expressed as a weighted proportion of available space.
///
Star,
}
///
/// GridLength is the type used for various length-like properties in the system,
/// that explicitely support Star unit type. For example, "Width", "Height"
/// properties of ColumnDefinition and RowDefinition used by Grid.
///
[TypeConverter(typeof(GridLengthConverter))]
public struct GridLength : IEquatable
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor, initializes the GridLength as absolute value in pixels.
///
/// Specifies the number of 'device-independent pixels'
/// (96 pixels-per-inch).
///
/// If pixels parameter is double.NaN
/// or pixels parameter is double.NegativeInfinity
/// or pixels parameter is double.PositiveInfinity .
///
public GridLength(double pixels)
: this(pixels, GridUnitType.Pixel)
{
}
///
/// Constructor, initializes the GridLength and specifies what kind of value
/// it will hold.
///
/// Value to be stored by this GridLength
/// instance.
/// Type of the value to be stored by this GridLength
/// instance.
///
/// If the type parameter is GridUnitType.Auto ,
/// then passed in value is ignored and replaced with 0 .
///
///
/// If value parameter is double.NaN
/// or value parameter is double.NegativeInfinity
/// or value parameter is double.PositiveInfinity .
///
public GridLength(double value, GridUnitType type)
{
if (DoubleUtil.IsNaN(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value"));
}
if (double.IsInfinity(value))
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoInfinity, "value"));
}
if ( type != GridUnitType.Auto
&& type != GridUnitType.Pixel
&& type != GridUnitType.Star )
{
throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterUnknownGridUnitType, "type"));
}
_unitValue = (type == GridUnitType.Auto) ? 0.0 : value;
_unitType = type;
}
#endregion Constructors
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Overloaded operator, compares 2 GridLength's.
///
/// first GridLength to compare.
/// second GridLength to compare.
/// true if specified GridLengths have same value
/// and unit type.
public static bool operator == (GridLength gl1, GridLength gl2)
{
return ( gl1.GridUnitType == gl2.GridUnitType
&& gl1.Value == gl2.Value );
}
///
/// Overloaded operator, compares 2 GridLength's.
///
/// first GridLength to compare.
/// second GridLength to compare.
/// true if specified GridLengths have either different value or
/// unit type.
public static bool operator != (GridLength gl1, GridLength gl2)
{
return ( gl1.GridUnitType != gl2.GridUnitType
|| gl1.Value != gl2.Value );
}
///
/// Compares this instance of GridLength with another object.
///
/// Reference to an object for comparison.
/// true if this GridLength instance has the same value
/// and unit type as oCompare.
override public bool Equals(object oCompare)
{
if(oCompare is GridLength)
{
GridLength l = (GridLength)oCompare;
return (this == l);
}
else
return false;
}
///
/// Compares this instance of GridLength with another instance.
///
/// Grid length instance to compare.
/// true if this GridLength instance has the same value
/// and unit type as gridLength.
public bool Equals(GridLength gridLength)
{
return (this == gridLength);
}
///
///
///
///
public override int GetHashCode()
{
return ((int)_unitValue + (int)_unitType);
}
///
/// Returns true if this GridLength instance holds
/// an absolute (pixel) value.
///
public bool IsAbsolute { get { return (_unitType == GridUnitType.Pixel); } }
///
/// Returns true if this GridLength instance is
/// automatic (not specified).
///
public bool IsAuto { get { return (_unitType == GridUnitType.Auto); } }
///
/// Returns true if this GridLength instance holds weighted propertion
/// of available space.
///
public bool IsStar { get { return (_unitType == GridUnitType.Star); } }
///
/// Returns value part of this GridLength instance.
///
public double Value { get { return ((_unitType == GridUnitType.Auto) ? 1.0 : _unitValue); } }
///
/// Returns unit type of this GridLength instance.
///
public GridUnitType GridUnitType { get { return (_unitType); } }
///
/// Returns the string representation of this object.
///
public override string ToString()
{
return GridLengthConverter.ToString(this, CultureInfo.InvariantCulture);
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
#region Public Properties
///
/// Returns initialized Auto GridLength value.
///
public static GridLength Auto
{
get { return (s_auto); }
}
#endregion Public Properties
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private double _unitValue; // unit value storage
private GridUnitType _unitType; // unit type storage
// static instance of Auto GridLength
private static readonly GridLength s_auto = new GridLength(1.0, GridUnitType.Auto);
#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
- JpegBitmapEncoder.cs
- DSACryptoServiceProvider.cs
- ChannelEndpointElement.cs
- StaticTextPointer.cs
- TemplateBindingExpression.cs
- QilScopedVisitor.cs
- TextBoxDesigner.cs
- ConsumerConnectionPointCollection.cs
- DefaultAutoFieldGenerator.cs
- BrowserCapabilitiesFactory.cs
- LocalizableAttribute.cs
- CodePageEncoding.cs
- SiteMapSection.cs
- PrintPageEvent.cs
- CompositeFontInfo.cs
- SqlCacheDependencyDatabaseCollection.cs
- DataSourceCollectionBase.cs
- NetCodeGroup.cs
- EntityDataSourceView.cs
- CLRBindingWorker.cs
- PartDesigner.cs
- TextProperties.cs
- LockCookie.cs
- ConfigXmlCDataSection.cs
- OletxVolatileEnlistment.cs
- ValidatorCompatibilityHelper.cs
- DESCryptoServiceProvider.cs
- XmlArrayItemAttribute.cs
- ApplicationHost.cs
- ScaleTransform.cs
- Crc32.cs
- Crc32.cs
- IteratorAsyncResult.cs
- X509Utils.cs
- FileChangesMonitor.cs
- ColorConverter.cs
- AspNetCacheProfileAttribute.cs
- CustomErrorsSectionWrapper.cs
- ObjectListCommandsPage.cs
- CopyOnWriteList.cs
- HttpPostedFile.cs
- TCEAdapterGenerator.cs
- ApplyHostConfigurationBehavior.cs
- DependencyPropertyHelper.cs
- SemanticAnalyzer.cs
- RectKeyFrameCollection.cs
- TreeWalkHelper.cs
- FormsAuthenticationEventArgs.cs
- Console.cs
- Point3D.cs
- UriParserTemplates.cs
- BindableTemplateBuilder.cs
- LineServicesCallbacks.cs
- Rect.cs
- UidManager.cs
- XmlBinaryReader.cs
- While.cs
- SystemIPv6InterfaceProperties.cs
- TextDecorationUnitValidation.cs
- GroupStyle.cs
- SpellerStatusTable.cs
- ListBox.cs
- FixedSOMTextRun.cs
- BitmapFrameDecode.cs
- HttpRequestCacheValidator.cs
- DesignTimeVisibleAttribute.cs
- TextTreeInsertUndoUnit.cs
- DesignerTransactionCloseEvent.cs
- Rule.cs
- NativeMethods.cs
- LabelDesigner.cs
- QueryOpeningEnumerator.cs
- HtmlValidationSummaryAdapter.cs
- ValidationError.cs
- CaseKeyBox.xaml.cs
- FormatConvertedBitmap.cs
- StrongNamePublicKeyBlob.cs
- TablePatternIdentifiers.cs
- ScriptingWebServicesSectionGroup.cs
- AsyncOperation.cs
- DataSourceExpression.cs
- PcmConverter.cs
- GridEntryCollection.cs
- ControlCommandSet.cs
- GlobalizationAssembly.cs
- DeferredTextReference.cs
- DataGridViewUtilities.cs
- ResourceReader.cs
- BlockUIContainer.cs
- XmlSchemaComplexContentRestriction.cs
- ScrollItemPatternIdentifiers.cs
- XmlDataDocument.cs
- SmtpFailedRecipientException.cs
- ToolStripPanelRenderEventArgs.cs
- SecurityException.cs
- NetworkInterface.cs
- SchemaMerger.cs
- CatalogPartChrome.cs
- EntityKeyElement.cs
- PolicyLevel.cs