AdornerPanel 类
更新:2007 年 11 月
为在设计时用作装饰器的 Windows 演示基础 (WPF) 控件提供容器。
命名空间: Microsoft.Windows.Design.Interaction
程序集: Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)
语法
声明
Public Class AdornerPanel _
Inherits Panel
用法
Dim instance As AdornerPanel
public class AdornerPanel : Panel
public ref class AdornerPanel : public Panel
public class AdornerPanel extends Panel
备注
使用 AdornerPanel 类来存放设计时装饰器。装饰器 是装饰一块用户界面 (UI) 的另一块 UI。
将表示装饰器的控件添加到 Children 集合。
调用 SetHorizontalStretch 和 SetVerticalStretch 方法可相对于所装饰的控件调整装饰器面板的大小。
要调整装饰器的大小并对其进行定位,应创建一个 AdornerPlacementCollection 并调用其与大小和位置有关的方法。使用 SetPlacements 方法将 AdornerPlacementCollection 添加到装饰器面板。
装饰器面板设置好后,将它添加到 AdornerProvider 实现的 Adorners 集合。
装饰器通过 Tool 附加属性绑定到工具命令。当鼠标悬停于装饰器上时,装饰器的绑定可用作输入和命令路由的一部分。此外,当装饰器处于活动状态时,与所装饰的 UI 元素关联的模型将成为所生成的任何笔势数据的“源”值。
示例
下面的代码示例演示如何使用 AdornerPanel 来承载 Slider 控件,该控件在设计时用来设置所装饰的控件的 Background 属性。有关更多信息,请参见 演练:创建设计时装饰器。
' 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);
继承层次结构
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
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Windows.Design.Interaction 命名空间