Udostępnij za pośrednictwem


AdornerPanel Class

Provides a container for Windows Presentation foundation (WPF) controls, which are used at design time as adorners.

Namespace:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)

Syntax

'Declaration
Public Class AdornerPanel _
    Inherits Panel
'Usage
Dim instance As AdornerPanel
public class AdornerPanel : Panel
public ref class AdornerPanel : public Panel
public class AdornerPanel extends Panel

Remarks

Use the AdornerPanel class to hold design-time adorners. An adorner is a piece of user interface (UI) that adorns another piece of UI.

Add controls that will represent adorners to the Children collection.

Call the SetHorizontalStretch and SetVerticalStretch methods to size the adorner panel relative to the adorned control.

To size and position adorners, create an AdornerPlacementCollection and call its size- and position-related methods. Add the AdornerPlacementCollection to the adorner panel by using the SetPlacements method.

When your adorner panel is set up, add it to the Adorners collection of an AdornerProvider implementation.

Adorners are bound to tool commands through the Tool attached property. When a mouse hovers over an adorner, the adorner’s bindings are available as part of the input and command routing. Also, the model associated with the adorned UI element becomes the "source" value of any gesture data that is generated when the adorner is active.

Examples

The following code example shows how to use an AdornerPanel to host a Slider control, which is used at design-time to set the Background property of the adorned control. For more information, see Walkthrough: Creating a Design-time Adorner.

' Setup the adorner panel. 
' All adorners are placed in an AdornerPanel 
' for sizing and layout support. 
Dim myPanel = Me.Panel

AdornerPanel.SetHorizontalStretch(opacitySlider, AdornerStretch.Stretch)
AdornerPanel.SetVerticalStretch(opacitySlider, AdornerStretch.None)

Dim placement As New AdornerPlacementCollection()

' The adorner's width is relative to the content. 
' The slider extends the full width of the control it adorns.
placement.SizeRelativeToContentWidth(1.0, 0)

' The adorner's height is the same as the slider's.
placement.SizeRelativeToAdornerDesiredHeight(1.0, 0)

' Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0)

' Position the adorner up 5 pixels. This demonstrates  
' that these placement calls are additive. These two calls 
' are equivalent to the following single call: 
' PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5)

AdornerPanel.SetPlacements(opacitySlider, placement)
// Setup the adorner panel. 
// All adorners are placed in an AdornerPanel 
// for sizing and layout support.
AdornerPanel myPanel = this.Panel;

AdornerPanel.SetHorizontalStretch(opacitySlider, AdornerStretch.Stretch);
AdornerPanel.SetVerticalStretch(opacitySlider, AdornerStretch.None);

AdornerPlacementCollection placement = new AdornerPlacementCollection();

// The adorner's width is relative to the content. 
// The slider extends the full width of the control it adorns.
placement.SizeRelativeToContentWidth(1.0, 0);

// The adorner's height is the same as the slider's.
placement.SizeRelativeToAdornerDesiredHeight(1.0, 0);

// Position the adorner above the control it adorns.
placement.PositionRelativeToAdornerHeight(-1.0, 0);

// Position the adorner up 5 pixels. This demonstrates  
// that these placement calls are additive. These two calls 
// are equivalent to the following single call: 
// PositionRelativeToAdornerHeight(-1.0, -5).
placement.PositionRelativeToAdornerHeight(0, -5);

AdornerPanel.SetPlacements(opacitySlider, placement);

Inheritance Hierarchy

System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Panel
              Microsoft.Windows.Design.Interaction.AdornerPanel

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

AdornerPanel Members

Microsoft.Windows.Design.Interaction Namespace

Other Resources

Adorner Architecture

Layout Space and Render Space

Feature Providers and Feature Connectors