Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Controls / Decorator.cs / 1 / Decorator.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: Border.cs
//
// Description: Contains the Decorator class.
// Spec at http://avalon/layout/Specs/Decorator.xml
//
// History:
// 06/12/2003 : greglett - Added to WCP branch
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.Controls;
using MS.Utility;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading;
using System.Windows.Media;
using System.Windows.Markup; // IAddChild, ContentPropertyAttribute
namespace System.Windows.Controls
{
///
/// Decorator is a base class for elements that apply effects onto or around a single child.
///
[Localizability(LocalizationCategory.Ignore, Readability = Readability.Unreadable)]
[ContentProperty("Child")]
public class Decorator : FrameworkElement, IAddChild
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Default DependencyObject constructor
///
///
/// Automatic determination of current Dispatcher. Use alternative constructor
/// that accepts a Dispatcher for best performance.
///
public Decorator() : base()
{
}
#endregion
//--------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------
#region Public Methods
///
/// This method is called to Add the object as a child of the Decorator. This method is used primarily
/// by the parser; a more direct way of adding a child to a Decorator is to use the
/// property.
///
///
/// The object to add as a child; it must be a UIElement.
///
void IAddChild.AddChild (Object value)
{
if (!(value is UIElement))
{
throw new ArgumentException (SR.Get(SRID.UnexpectedParameterType, value.GetType(), typeof(UIElement)), "value");
}
if (this.Child != null)
{
throw new ArgumentException(SR.Get(SRID.CanOnlyHaveOneChild, this.GetType(), value.GetType()));
}
this.Child = (UIElement)value;
}
///
/// This method is called by the parser when text appears under the tag in markup.
/// As Decorators do not support text, calling this method has no effect if the text
/// is all whitespace. For non-whitespace text, throw an exception.
///
///
/// Text to add as a child.
///
void IAddChild.AddText (string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
#endregion
//--------------------------------------------------------------------
//
// Public Properties
//
//--------------------------------------------------------------------
#region Public Properties
///
/// The single child of a
///
[DefaultValue(null)]
public virtual UIElement Child
{
get
{
return _child;
}
set
{
if(_child != value)
{
// notify the visual layer that the old child has been removed.
RemoveVisualChild(_child);
//need to remove old element from logical tree
RemoveLogicalChild(_child);
_child = value;
AddLogicalChild(value);
// notify the visual layer about the new child.
AddVisualChild(value);
InvalidateMeasure();
}
}
}
///
/// Returns enumerator to logical children.
///
protected internal override IEnumerator LogicalChildren
{
get
{
if (_child == null)
{
return EmptyEnumerator.Instance;
}
return new SingleChildEnumerator(_child);
}
}
#endregion
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
#region Protected Methods
///
/// Returns the Visual children count.
///
protected override int VisualChildrenCount
{
get { return (_child == null) ? 0 : 1; }
}
///
/// Returns the child at the specified index.
///
protected override Visual GetVisualChild(int index)
{
if ( (_child == null)
|| (index != 0))
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return _child;
}
///
/// Updates DesiredSize of the Decorator. Called by parent UIElement. This is the first pass of layout.
///
///
/// Decorator determines a desired size it needs from the child's sizing properties, margin, and requested size.
///
/// Constraint size is an "upper limit" that the return value should not exceed.
/// The Decorator's desired size.
protected override Size MeasureOverride(Size constraint)
{
UIElement child = Child;
if (child != null)
{
Helper.SetMeasureDataOnChild(this, child, constraint); // pass along MeasureData so it continues down the tree.
child.Measure(constraint);
return (child.DesiredSize);
}
return (new Size());
}
///
/// Decorator computes the position of its single child inside child's Margin and calls Arrange
/// on the child.
///
/// Size the Decorator will assume.
protected override Size ArrangeOverride(Size arrangeSize)
{
UIElement child = Child;
if (child != null)
{
child.Arrange(new Rect(arrangeSize));
}
return (arrangeSize);
}
#endregion
#region Internal Properties
internal UIElement IntChild
{
get { return _child; }
set { _child = value; }
}
#endregion
#region Private Members
UIElement _child;
#endregion Private Members
}
}
// 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.
//
// File: Border.cs
//
// Description: Contains the Decorator class.
// Spec at http://avalon/layout/Specs/Decorator.xml
//
// History:
// 06/12/2003 : greglett - Added to WCP branch
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.Controls;
using MS.Utility;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading;
using System.Windows.Media;
using System.Windows.Markup; // IAddChild, ContentPropertyAttribute
namespace System.Windows.Controls
{
///
/// Decorator is a base class for elements that apply effects onto or around a single child.
///
[Localizability(LocalizationCategory.Ignore, Readability = Readability.Unreadable)]
[ContentProperty("Child")]
public class Decorator : FrameworkElement, IAddChild
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Default DependencyObject constructor
///
///
/// Automatic determination of current Dispatcher. Use alternative constructor
/// that accepts a Dispatcher for best performance.
///
public Decorator() : base()
{
}
#endregion
//--------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------
#region Public Methods
///
/// This method is called to Add the object as a child of the Decorator. This method is used primarily
/// by the parser; a more direct way of adding a child to a Decorator is to use the
/// property.
///
///
/// The object to add as a child; it must be a UIElement.
///
void IAddChild.AddChild (Object value)
{
if (!(value is UIElement))
{
throw new ArgumentException (SR.Get(SRID.UnexpectedParameterType, value.GetType(), typeof(UIElement)), "value");
}
if (this.Child != null)
{
throw new ArgumentException(SR.Get(SRID.CanOnlyHaveOneChild, this.GetType(), value.GetType()));
}
this.Child = (UIElement)value;
}
///
/// This method is called by the parser when text appears under the tag in markup.
/// As Decorators do not support text, calling this method has no effect if the text
/// is all whitespace. For non-whitespace text, throw an exception.
///
///
/// Text to add as a child.
///
void IAddChild.AddText (string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
#endregion
//--------------------------------------------------------------------
//
// Public Properties
//
//--------------------------------------------------------------------
#region Public Properties
///
/// The single child of a
///
[DefaultValue(null)]
public virtual UIElement Child
{
get
{
return _child;
}
set
{
if(_child != value)
{
// notify the visual layer that the old child has been removed.
RemoveVisualChild(_child);
//need to remove old element from logical tree
RemoveLogicalChild(_child);
_child = value;
AddLogicalChild(value);
// notify the visual layer about the new child.
AddVisualChild(value);
InvalidateMeasure();
}
}
}
///
/// Returns enumerator to logical children.
///
protected internal override IEnumerator LogicalChildren
{
get
{
if (_child == null)
{
return EmptyEnumerator.Instance;
}
return new SingleChildEnumerator(_child);
}
}
#endregion
//-------------------------------------------------------------------
//
// Protected Methods
//
//--------------------------------------------------------------------
#region Protected Methods
///
/// Returns the Visual children count.
///
protected override int VisualChildrenCount
{
get { return (_child == null) ? 0 : 1; }
}
///
/// Returns the child at the specified index.
///
protected override Visual GetVisualChild(int index)
{
if ( (_child == null)
|| (index != 0))
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return _child;
}
///
/// Updates DesiredSize of the Decorator. Called by parent UIElement. This is the first pass of layout.
///
///
/// Decorator determines a desired size it needs from the child's sizing properties, margin, and requested size.
///
/// Constraint size is an "upper limit" that the return value should not exceed.
/// The Decorator's desired size.
protected override Size MeasureOverride(Size constraint)
{
UIElement child = Child;
if (child != null)
{
Helper.SetMeasureDataOnChild(this, child, constraint); // pass along MeasureData so it continues down the tree.
child.Measure(constraint);
return (child.DesiredSize);
}
return (new Size());
}
///
/// Decorator computes the position of its single child inside child's Margin and calls Arrange
/// on the child.
///
/// Size the Decorator will assume.
protected override Size ArrangeOverride(Size arrangeSize)
{
UIElement child = Child;
if (child != null)
{
child.Arrange(new Rect(arrangeSize));
}
return (arrangeSize);
}
#endregion
#region Internal Properties
internal UIElement IntChild
{
get { return _child; }
set { _child = value; }
}
#endregion
#region Private Members
UIElement _child;
#endregion Private Members
}
}
// 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
- IssuedTokenServiceElement.cs
- tooltip.cs
- CopyNamespacesAction.cs
- DbQueryCommandTree.cs
- QueryOutputWriter.cs
- DesignerWebPartChrome.cs
- DefaultObjectMappingItemCollection.cs
- CollectionChangedEventManager.cs
- Crypto.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- CodeIterationStatement.cs
- XmlDocumentSerializer.cs
- FrugalMap.cs
- Light.cs
- WindowPattern.cs
- TagPrefixAttribute.cs
- TdsValueSetter.cs
- StorageEntitySetMapping.cs
- ConfigsHelper.cs
- XamlDesignerSerializationManager.cs
- IndentTextWriter.cs
- Soap.cs
- Vertex.cs
- XamlNamespaceHelper.cs
- AssemblyBuilder.cs
- HandleTable.cs
- FillErrorEventArgs.cs
- Timer.cs
- ExeConfigurationFileMap.cs
- ContextMenu.cs
- CorrelationTokenTypeConvertor.cs
- CollectionDataContract.cs
- HttpServerVarsCollection.cs
- XmlDocumentFragment.cs
- Brushes.cs
- IdentityNotMappedException.cs
- SystemParameters.cs
- TrackingMemoryStream.cs
- TextTreeUndoUnit.cs
- GuidConverter.cs
- ByteStack.cs
- DbInsertCommandTree.cs
- Converter.cs
- RangeValidator.cs
- WebPartZoneCollection.cs
- TimeoutValidationAttribute.cs
- rsa.cs
- ToolStripDesigner.cs
- XmlDownloadManager.cs
- WebPartCollection.cs
- TreeViewItem.cs
- XmlSchemaSimpleContentRestriction.cs
- documentation.cs
- DesignerDataParameter.cs
- DocumentOrderQuery.cs
- EmbeddedMailObjectsCollection.cs
- DbDataRecord.cs
- MimeTypePropertyAttribute.cs
- ContractTypeNameCollection.cs
- WindowsListViewGroup.cs
- CodeDomConfigurationHandler.cs
- DependencyPropertyHelper.cs
- XPathBinder.cs
- TextMarkerSource.cs
- DetailsViewInsertEventArgs.cs
- TimeEnumHelper.cs
- XmlConvert.cs
- IdentifierService.cs
- DataDesignUtil.cs
- XmlLinkedNode.cs
- CreateUserWizardStep.cs
- JournalEntry.cs
- DataViewListener.cs
- GacUtil.cs
- PackWebRequest.cs
- TimerElapsedEvenArgs.cs
- ParameterModifier.cs
- Stroke.cs
- GCHandleCookieTable.cs
- UnaryNode.cs
- ModelVisual3D.cs
- RegexCharClass.cs
- WebControlParameterProxy.cs
- ItemsControl.cs
- MultiPartWriter.cs
- ImageCodecInfo.cs
- WrappedIUnknown.cs
- WorkflowRuntimeServiceElement.cs
- RadioButtonAutomationPeer.cs
- ThreadAttributes.cs
- InteropBitmapSource.cs
- OverrideMode.cs
- CodeSpit.cs
- TagPrefixAttribute.cs
- DeferrableContentConverter.cs
- CDSCollectionETWBCLProvider.cs
- ColorAnimation.cs
- WebResourceAttribute.cs
- SrgsGrammar.cs
- PromptStyle.cs