Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Controls / AdornedElementPlaceholder.cs / 1 / AdornedElementPlaceholder.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//
//
// Description:
// AdornedElementPlaceholder is an element used in a Binding.ErrorTemplate.
// Its purpose is to mimic the height and width of the AdornedElement so that
// other elements in Template can be arranged around or within it.
//
// See specs at http://avalon/connecteddata/Specs/Validation.mht
//
// History:
// 02/01/2005 mharper: created.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Media;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Markup;
using MS.Internal.Controls;
using MS.Utility;
namespace System.Windows.Controls
{
///
/// The base class for all controls.
///
[ContentProperty("Child")]
public class AdornedElementPlaceholder : FrameworkElement, IAddChild
{
#region Constructors
///
/// Default Control constructor
///
///
/// Automatic determination of current Dispatcher. Use alternative constructor
/// that accepts a Dispatcher for best performance.
///
public AdornedElementPlaceholder() : base()
{
}
#endregion Constructors
///
/// This method is called to Add the object as a child. This method is used primarily
/// by the parser; a more direct way of adding a child is to use the
/// property.
///
///
/// The object to add as a child; it must be a UIElement.
///
void IAddChild.AddChild (Object value)
{
// keeping consistent with other elements: adding null is a no-op.
if (value == null)
return;
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.
/// Calling this method has no effect if text is just whitespace. If text is not
/// just whitespace, throw an exception.
///
///
/// Text to add as a child.
///
void IAddChild.AddText (string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
///
/// Element for which the AdornedElementPlaceholder is reserving space.
///
public UIElement AdornedElement
{
get
{
TemplatedAdorner adorner = TemplatedAdorner;
return adorner == null ? null : TemplatedAdorner.AdornedElement;
}
}
///
/// The single child of an
///
[DefaultValue(null)]
public virtual UIElement Child
{
get
{
return _child;
}
set
{
UIElement old = _child;
if (old != value)
{
RemoveVisualChild(old);
//need to remove old element from logical tree
RemoveLogicalChild(old);
_child = value;
AddVisualChild(_child);
AddLogicalChild(value);
InvalidateMeasure();
}
}
}
///
/// Gets the Visual children count.
///
protected override int VisualChildrenCount
{
get
{
return (_child == null) ? 0 : 1;
}
}
///
/// Gets the Visual 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;
}
///
/// Returns enumerator to logical children.
///
protected internal override IEnumerator LogicalChildren
{
get
{
// Could optimize this code by returning EmptyEnumerator.Instance if _child == null.
return new SingleChildEnumerator(_child);
}
}
///
/// This virtual method in called when IsInitialized is set to true and it raises an Initialized event
///
protected override void OnInitialized(EventArgs e)
{
if (TemplatedParent == null)
throw new InvalidOperationException(SR.Get(SRID.AdornedElementPlaceholderMustBeInTemplate));
base.OnInitialized(e);
}
///
/// AdornedElementPlaceholder measure behavior is to measure
/// only the first visual child. Note that the return value
/// of Measure on this child is ignored as the purpose of this
/// class is to match the size of the element for which this
/// is a placeholder.
///
/// The measurement constraints.
/// The desired size of the control.
protected override Size MeasureOverride(Size constraint)
{
if (TemplatedParent == null)
throw new InvalidOperationException(SR.Get(SRID.AdornedElementPlaceholderMustBeInTemplate));
if (AdornedElement == null)
return new Size(0,0);
Size desiredSize = AdornedElement.RenderSize;
UIElement child = Child;
if (child != null)
child.Measure(desiredSize);
return desiredSize;
}
///
/// Default AdornedElementPlaceholder arrangement is to only arrange
/// the first visual child. No transforms will be applied.
///
/// The computed size.
protected override Size ArrangeOverride(Size arrangeBounds)
{
UIElement child = Child;
if (child != null)
child.Arrange(new Rect(arrangeBounds));
return arrangeBounds;
}
private TemplatedAdorner TemplatedAdorner
{
get
{
if (_templatedAdorner == null)
{
// find the TemplatedAdorner
FrameworkElement templateParent = this.TemplatedParent as FrameworkElement;
if (templateParent != null)
{
_templatedAdorner = VisualTreeHelper.GetParent(templateParent) as TemplatedAdorner;
if (_templatedAdorner != null && _templatedAdorner.ReferenceElement == null)
{
_templatedAdorner.ReferenceElement = this;
}
}
}
return _templatedAdorner;
}
}
private UIElement _child;
private TemplatedAdorner _templatedAdorner;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//
//
// Description:
// AdornedElementPlaceholder is an element used in a Binding.ErrorTemplate.
// Its purpose is to mimic the height and width of the AdornedElement so that
// other elements in Template can be arranged around or within it.
//
// See specs at http://avalon/connecteddata/Specs/Validation.mht
//
// History:
// 02/01/2005 mharper: created.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Media;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Markup;
using MS.Internal.Controls;
using MS.Utility;
namespace System.Windows.Controls
{
///
/// The base class for all controls.
///
[ContentProperty("Child")]
public class AdornedElementPlaceholder : FrameworkElement, IAddChild
{
#region Constructors
///
/// Default Control constructor
///
///
/// Automatic determination of current Dispatcher. Use alternative constructor
/// that accepts a Dispatcher for best performance.
///
public AdornedElementPlaceholder() : base()
{
}
#endregion Constructors
///
/// This method is called to Add the object as a child. This method is used primarily
/// by the parser; a more direct way of adding a child is to use the
/// property.
///
///
/// The object to add as a child; it must be a UIElement.
///
void IAddChild.AddChild (Object value)
{
// keeping consistent with other elements: adding null is a no-op.
if (value == null)
return;
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.
/// Calling this method has no effect if text is just whitespace. If text is not
/// just whitespace, throw an exception.
///
///
/// Text to add as a child.
///
void IAddChild.AddText (string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
///
/// Element for which the AdornedElementPlaceholder is reserving space.
///
public UIElement AdornedElement
{
get
{
TemplatedAdorner adorner = TemplatedAdorner;
return adorner == null ? null : TemplatedAdorner.AdornedElement;
}
}
///
/// The single child of an
///
[DefaultValue(null)]
public virtual UIElement Child
{
get
{
return _child;
}
set
{
UIElement old = _child;
if (old != value)
{
RemoveVisualChild(old);
//need to remove old element from logical tree
RemoveLogicalChild(old);
_child = value;
AddVisualChild(_child);
AddLogicalChild(value);
InvalidateMeasure();
}
}
}
///
/// Gets the Visual children count.
///
protected override int VisualChildrenCount
{
get
{
return (_child == null) ? 0 : 1;
}
}
///
/// Gets the Visual 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;
}
///
/// Returns enumerator to logical children.
///
protected internal override IEnumerator LogicalChildren
{
get
{
// Could optimize this code by returning EmptyEnumerator.Instance if _child == null.
return new SingleChildEnumerator(_child);
}
}
///
/// This virtual method in called when IsInitialized is set to true and it raises an Initialized event
///
protected override void OnInitialized(EventArgs e)
{
if (TemplatedParent == null)
throw new InvalidOperationException(SR.Get(SRID.AdornedElementPlaceholderMustBeInTemplate));
base.OnInitialized(e);
}
///
/// AdornedElementPlaceholder measure behavior is to measure
/// only the first visual child. Note that the return value
/// of Measure on this child is ignored as the purpose of this
/// class is to match the size of the element for which this
/// is a placeholder.
///
/// The measurement constraints.
/// The desired size of the control.
protected override Size MeasureOverride(Size constraint)
{
if (TemplatedParent == null)
throw new InvalidOperationException(SR.Get(SRID.AdornedElementPlaceholderMustBeInTemplate));
if (AdornedElement == null)
return new Size(0,0);
Size desiredSize = AdornedElement.RenderSize;
UIElement child = Child;
if (child != null)
child.Measure(desiredSize);
return desiredSize;
}
///
/// Default AdornedElementPlaceholder arrangement is to only arrange
/// the first visual child. No transforms will be applied.
///
/// The computed size.
protected override Size ArrangeOverride(Size arrangeBounds)
{
UIElement child = Child;
if (child != null)
child.Arrange(new Rect(arrangeBounds));
return arrangeBounds;
}
private TemplatedAdorner TemplatedAdorner
{
get
{
if (_templatedAdorner == null)
{
// find the TemplatedAdorner
FrameworkElement templateParent = this.TemplatedParent as FrameworkElement;
if (templateParent != null)
{
_templatedAdorner = VisualTreeHelper.GetParent(templateParent) as TemplatedAdorner;
if (_templatedAdorner != null && _templatedAdorner.ReferenceElement == null)
{
_templatedAdorner.ReferenceElement = this;
}
}
}
return _templatedAdorner;
}
}
private UIElement _child;
private TemplatedAdorner _templatedAdorner;
}
}
// 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
- IntegerValidator.cs
- FlowDocumentReader.cs
- BuildProvider.cs
- _ListenerRequestStream.cs
- Panel.cs
- FixedHighlight.cs
- BinaryEditor.cs
- HttpRequestCacheValidator.cs
- XmlSchemaValidationException.cs
- PageFunction.cs
- Events.cs
- UserInitiatedNavigationPermission.cs
- TrackingServices.cs
- SqlDataSourceSelectingEventArgs.cs
- WebPartTransformerAttribute.cs
- ADMembershipProvider.cs
- LabelLiteral.cs
- CodeCommentStatementCollection.cs
- CallbackValidatorAttribute.cs
- BooleanProjectedSlot.cs
- MeshGeometry3D.cs
- Ref.cs
- RouteValueDictionary.cs
- HtmlInputText.cs
- TextRunTypographyProperties.cs
- ErrorTableItemStyle.cs
- EllipseGeometry.cs
- RelatedImageListAttribute.cs
- TagNameToTypeMapper.cs
- ZeroOpNode.cs
- BitmapImage.cs
- SafeWaitHandle.cs
- ColorAnimationUsingKeyFrames.cs
- SchemaObjectWriter.cs
- TimersDescriptionAttribute.cs
- HtmlWindowCollection.cs
- Bold.cs
- EnumerableRowCollection.cs
- XmlSchema.cs
- CapiSymmetricAlgorithm.cs
- ServiceTimeoutsElement.cs
- XmlNamespaceDeclarationsAttribute.cs
- WebBrowsableAttribute.cs
- TrackingWorkflowEventArgs.cs
- DictionaryContent.cs
- ValidationError.cs
- DataGridViewRowPrePaintEventArgs.cs
- BitmapEffectDrawingContextState.cs
- HyperLinkStyle.cs
- Drawing.cs
- FrugalList.cs
- CodeNamespaceImportCollection.cs
- SynchronizationLockException.cs
- PointAnimation.cs
- AppSettingsReader.cs
- RepeatBehaviorConverter.cs
- CodeTypeDeclaration.cs
- WebPartRestoreVerb.cs
- Tuple.cs
- CannotUnloadAppDomainException.cs
- Stylesheet.cs
- NumberFormatter.cs
- ComponentCollection.cs
- SessionEndingCancelEventArgs.cs
- SafeSecurityHandles.cs
- TableAdapterManagerMethodGenerator.cs
- BatchStream.cs
- NavigationEventArgs.cs
- XmlDocumentFragment.cs
- SctClaimSerializer.cs
- DataListItem.cs
- IPEndPoint.cs
- NullRuntimeConfig.cs
- AssemblyCollection.cs
- ResetableIterator.cs
- CornerRadius.cs
- ByteViewer.cs
- BackgroundFormatInfo.cs
- EntityDataSourceContainerNameItem.cs
- BrowserDefinition.cs
- EntityCommandExecutionException.cs
- GPRECT.cs
- WeakReadOnlyCollection.cs
- Inline.cs
- GenericPrincipal.cs
- VectorAnimationBase.cs
- AssemblyCollection.cs
- DataGridViewRowConverter.cs
- DifferencingCollection.cs
- DBDataPermissionAttribute.cs
- HttpStreamXmlDictionaryWriter.cs
- ObjectQueryExecutionPlan.cs
- FlowchartDesignerCommands.cs
- ReadWriteSpinLock.cs
- GPPOINT.cs
- ContainerCodeDomSerializer.cs
- ListBoxItemWrapperAutomationPeer.cs
- AudioBase.cs
- PerspectiveCamera.cs
- ReadingWritingEntityEventArgs.cs