Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / MS / Internal / Controls / TemplatedAdorner.cs / 1 / TemplatedAdorner.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//
//
// Description:
// TemplatedAdorner applies the style provided in the ctor to a
// control and provides a transform via GetDesiredTransform that
// will cause the AdornedElementPlaceholder to be positioned directly
// over the AdornedElement.
//
// 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.Controls;
using System.Windows.Documents;
using MS.Utility;
namespace MS.Internal.Controls
{
///
/// This class is sealed because it calls OnVisualChildrenChanged virtual in the
/// constructor and it does not override it, but derived classes could.
///
internal sealed class TemplatedAdorner: Adorner
{
private Control _child;
///
/// The clear the single child of a TemplatedAdorner
///
public void ClearChild()
{
this.RemoveVisualChild(_child);
_child = null;
}
public TemplatedAdorner(UIElement adornedElement, ControlTemplate adornerTemplate) : base(adornedElement)
{
Debug.Assert(adornedElement != null, "adornedElement should not be null");
Debug.Assert(adornerTemplate != null, "adornerTemplate should not be null");
Control control = new Control();
control.DataContext = Validation.GetErrors(adornedElement);
//control.IsEnabled = false; // Hittest should not work on visual subtree
control.Template = adornerTemplate;
_child = control;
this.AddVisualChild(_child);
}
///
/// Adorners don't always want to be transformed in the same way as the elements they
/// adorn. Adorners which adorn points, such as resize handles, want to be translated
/// and rotated but not scaled. Adorners adorning an object, like a marquee, may want
/// all transforms. This method is called by AdornerLayer to allow the adorner to
/// filter out the transforms it doesn't want and return a new transform with just the
/// transforms it wants applied. An adorner can also add an additional translation
/// transform at this time, allowing it to be positioned somewhere other than the upper
/// left corner of its adorned element.
///
/// The transform applied to the object the adorner adorns
/// Transform to apply to the adorner
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
if (ReferenceElement == null)
return transform;
GeneralTransformGroup group = new GeneralTransformGroup();
group.Children.Add(transform);
GeneralTransform t = this.TransformToDescendant(ReferenceElement);
if (t != null)
{
group.Children.Add(t);
}
return group;
}
public FrameworkElement ReferenceElement
{
get
{
return _referenceElement;
}
set
{
_referenceElement = value;
}
}
///
/// Derived class must implement to support Visual children. The method must return
/// the child at the specified index. Index must be between 0 and GetVisualChildrenCount-1.
///
/// By default a Visual does not have any children.
///
/// Remark:
/// During this virtual call it is not valid to modify the Visual tree.
///
protected override Visual GetVisualChild(int index)
{
if(_child == null || index != 0)
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return _child;
}
///
/// Derived classes override this property to enable the Visual code to enumerate
/// the Visual children. Derived classes need to return the number of children
/// from this method.
///
/// By default a Visual does not have any children.
///
/// Remark: During this virtual method the Visual tree must not be modified.
///
protected override int VisualChildrenCount
{
get { return _child != null ? 1 : 0; }
}
///
/// Measure adorner. Default behavior is to size to match the adorned element.
///
protected override Size MeasureOverride(Size constraint)
{
Debug.Assert(_child != null, "_child should not be null");
if (ReferenceElement != null && AdornedElement != null &&
AdornedElement.IsMeasureValid &&
!DoubleUtil.AreClose(ReferenceElement.DesiredSize, AdornedElement.DesiredSize)
)
{
ReferenceElement.InvalidateMeasure();
}
(_child).Measure(constraint);
return (_child).DesiredSize;
}
///
/// Default control arrangement is to only arrange
/// the first visual child. No transforms will be applied.
///
protected override Size ArrangeOverride(Size size)
{
Size finalSize;
finalSize = base.ArrangeOverride(size);
if (_child != null)
{
_child.Arrange(new Rect(new Point(), finalSize));
}
return finalSize;
}
private FrameworkElement _referenceElement;
}
}
// 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:
// TemplatedAdorner applies the style provided in the ctor to a
// control and provides a transform via GetDesiredTransform that
// will cause the AdornedElementPlaceholder to be positioned directly
// over the AdornedElement.
//
// 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.Controls;
using System.Windows.Documents;
using MS.Utility;
namespace MS.Internal.Controls
{
///
/// This class is sealed because it calls OnVisualChildrenChanged virtual in the
/// constructor and it does not override it, but derived classes could.
///
internal sealed class TemplatedAdorner: Adorner
{
private Control _child;
///
/// The clear the single child of a TemplatedAdorner
///
public void ClearChild()
{
this.RemoveVisualChild(_child);
_child = null;
}
public TemplatedAdorner(UIElement adornedElement, ControlTemplate adornerTemplate) : base(adornedElement)
{
Debug.Assert(adornedElement != null, "adornedElement should not be null");
Debug.Assert(adornerTemplate != null, "adornerTemplate should not be null");
Control control = new Control();
control.DataContext = Validation.GetErrors(adornedElement);
//control.IsEnabled = false; // Hittest should not work on visual subtree
control.Template = adornerTemplate;
_child = control;
this.AddVisualChild(_child);
}
///
/// Adorners don't always want to be transformed in the same way as the elements they
/// adorn. Adorners which adorn points, such as resize handles, want to be translated
/// and rotated but not scaled. Adorners adorning an object, like a marquee, may want
/// all transforms. This method is called by AdornerLayer to allow the adorner to
/// filter out the transforms it doesn't want and return a new transform with just the
/// transforms it wants applied. An adorner can also add an additional translation
/// transform at this time, allowing it to be positioned somewhere other than the upper
/// left corner of its adorned element.
///
/// The transform applied to the object the adorner adorns
/// Transform to apply to the adorner
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
if (ReferenceElement == null)
return transform;
GeneralTransformGroup group = new GeneralTransformGroup();
group.Children.Add(transform);
GeneralTransform t = this.TransformToDescendant(ReferenceElement);
if (t != null)
{
group.Children.Add(t);
}
return group;
}
public FrameworkElement ReferenceElement
{
get
{
return _referenceElement;
}
set
{
_referenceElement = value;
}
}
///
/// Derived class must implement to support Visual children. The method must return
/// the child at the specified index. Index must be between 0 and GetVisualChildrenCount-1.
///
/// By default a Visual does not have any children.
///
/// Remark:
/// During this virtual call it is not valid to modify the Visual tree.
///
protected override Visual GetVisualChild(int index)
{
if(_child == null || index != 0)
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return _child;
}
///
/// Derived classes override this property to enable the Visual code to enumerate
/// the Visual children. Derived classes need to return the number of children
/// from this method.
///
/// By default a Visual does not have any children.
///
/// Remark: During this virtual method the Visual tree must not be modified.
///
protected override int VisualChildrenCount
{
get { return _child != null ? 1 : 0; }
}
///
/// Measure adorner. Default behavior is to size to match the adorned element.
///
protected override Size MeasureOverride(Size constraint)
{
Debug.Assert(_child != null, "_child should not be null");
if (ReferenceElement != null && AdornedElement != null &&
AdornedElement.IsMeasureValid &&
!DoubleUtil.AreClose(ReferenceElement.DesiredSize, AdornedElement.DesiredSize)
)
{
ReferenceElement.InvalidateMeasure();
}
(_child).Measure(constraint);
return (_child).DesiredSize;
}
///
/// Default control arrangement is to only arrange
/// the first visual child. No transforms will be applied.
///
protected override Size ArrangeOverride(Size size)
{
Size finalSize;
finalSize = base.ArrangeOverride(size);
if (_child != null)
{
_child.Arrange(new Rect(new Point(), finalSize));
}
return finalSize;
}
private FrameworkElement _referenceElement;
}
}
// 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
- KeyValueSerializer.cs
- OleDbErrorCollection.cs
- TraceSection.cs
- MSAAEventDispatcher.cs
- XmlTextReader.cs
- FileDialogCustomPlace.cs
- DrawListViewSubItemEventArgs.cs
- TypeTypeConverter.cs
- MatrixValueSerializer.cs
- MatrixTransform3D.cs
- HttpAsyncResult.cs
- MatrixTransform3D.cs
- IPipelineRuntime.cs
- RenderCapability.cs
- XmlQueryRuntime.cs
- GridViewColumnCollection.cs
- AppDomainFactory.cs
- AppDomainFactory.cs
- TransformerConfigurationWizardBase.cs
- RelationalExpressions.cs
- FactoryId.cs
- SearchForVirtualItemEventArgs.cs
- DataServices.cs
- cookie.cs
- Bits.cs
- MobileSysDescriptionAttribute.cs
- CookieParameter.cs
- LoginName.cs
- BinaryUtilClasses.cs
- EventWaitHandle.cs
- Exceptions.cs
- Bidi.cs
- SystemParameters.cs
- XmlSerializerOperationGenerator.cs
- DataGridViewDataConnection.cs
- Setter.cs
- HashHelper.cs
- XmlChildEnumerator.cs
- ProgressPage.cs
- SizeValueSerializer.cs
- BoundColumn.cs
- WindowInteractionStateTracker.cs
- APCustomTypeDescriptor.cs
- StateMachineSubscriptionManager.cs
- CachedFontFace.cs
- ListBindingHelper.cs
- TextPenaltyModule.cs
- NavigatorInput.cs
- ConfigurationStrings.cs
- TrimSurroundingWhitespaceAttribute.cs
- WebPartsSection.cs
- HandlerFactoryWrapper.cs
- DateTimeFormatInfoScanner.cs
- XamlToRtfParser.cs
- Processor.cs
- SerialPort.cs
- Rule.cs
- WebPermission.cs
- ElementInit.cs
- BitArray.cs
- XmlObjectSerializerContext.cs
- Stroke.cs
- NetSectionGroup.cs
- RangeValuePattern.cs
- LinqDataSourceStatusEventArgs.cs
- TextBounds.cs
- WebPartVerbCollection.cs
- MeasureItemEvent.cs
- DSGeneratorProblem.cs
- TranslateTransform.cs
- HttpListenerRequestUriBuilder.cs
- XslVisitor.cs
- SourceSwitch.cs
- XmlSchemaObjectCollection.cs
- FileNotFoundException.cs
- CryptographicAttribute.cs
- Identity.cs
- DesignerActionPanel.cs
- ExecutionContext.cs
- LicenseException.cs
- DataGridViewCellStateChangedEventArgs.cs
- QilName.cs
- PreservationFileReader.cs
- SelectionItemProviderWrapper.cs
- MarkerProperties.cs
- FrameworkReadOnlyPropertyMetadata.cs
- SoapIncludeAttribute.cs
- CompoundFileStorageReference.cs
- Funcletizer.cs
- FileDetails.cs
- TypeInitializationException.cs
- OdbcError.cs
- FontDifferentiator.cs
- NativeMethods.cs
- TableParaClient.cs
- securestring.cs
- _Connection.cs
- DefaultBindingPropertyAttribute.cs
- DbReferenceCollection.cs
- CounterSample.cs